【问题标题】:Ubuntu 15 proceed codebird-php stream by cron not workscron 的 Ubuntu 15 继续 codebird-php 流不起作用
【发布时间】:2017-04-18 08:53:28
【问题描述】:

我有一个带有codebird-php lib 的 laravel 项目。我试图设置一个 cron 作业来开始调度我的流命令。
在我装有 Ubuntu 16 的本地机器上,它运行良好,每分钟都会创建一个流到 twitter,并在 55 秒时死掉。

但在远程 VPS 上,它没有安排我的命令。我已经通过 cron 尝试过,通过在终端中提示并且没有效果。谁能解释我在哪里犯了一个愚蠢的错误以及 cron 工作 Ubuntu 15.04 和 Ubuntu 16.04 有什么区别? 下面是命令代码: 连接命令设置流并启动它们

class ConnectToStreamingAPI extends Command
{

    protected $signature = 'connect';
    protected $run = [];

    protected $users;


    protected $description = 'Connect to the Twitter Streaming API to search tweets by keywords';

    protected $twitterStream;


    public function __construct(User $user)
    {
        $this->users = $user::where('id', '>', '1')->pluck('id')->toArray();
        parent::__construct();
    }


    public function handle()
    {
        //set_time_limit(59);
        $this->setRun();
        $this->runUserStreamCommand();

        return "Fired";

    }

    protected function setRun()
    {
        foreach ($this->users as $user) {
            $this->addToRun($user);
        }
    }

    protected function runUserStreamCommand()
    {
        foreach ($this->run as $process) {
            $process->setPty(true);
            $process->start();
        }
        $count = count($this->run);
        while (count($this->run) > 0) {
            foreach ($this->run as $key => $process) {
                $childProcess = $process->getPid() + $count;
                try {
                    $process->checkTimeout();
                } catch (ProcessTimedOutException $e) {
                    exec("kill -15 " . $childProcess);
                }
                if (!$process->isRunning()) {
                    unset($this->run[$key]);
                }
            }
        }

    }

    protected function addToRun($user_id)
    {
        $this->run[] = new Process("php /path/to/artisan stream $user_id", null, null, null, 50);
    }
}

这里是 Stream 命令

class StreamingCommands extends Command
{

    protected $signature = 'stream {id}';


    protected $description = 'create stream to twitter for one user';


    public function __construct()
    {
        parent::__construct();
    }


    public function handle()
    {
        $id = $this->argument('id');
        $user = User::find($id);
        Codebird::setConsumerKey($user->consumer_key, $user->consumer_secret);
        $stream = new TwitterStream();
        $stream->setToken($user->twitterData->token, $user->twitterData->token_secret);
        $keywordArray = array();
        $ids = array();
        foreach ($user->campaigns as $campaign) {
            $ids[] = $campaign->id;
            $keywordArray = array_merge($keywordArray, Keyword::whereCampaignId($campaign->id)->pluck('keyword')->toArray());
        }
        $keywords = Keyword::whereIn('campaign_id', $ids)->where('rejected', 0)->get();
        $stream->setKeywords($keywords);
        $stream->setStreamingCallback('processTweet');
        $keywords = implode(',', $keywordArray);
        $this->info("start stream to user $id");
        $stream->statuses_filter('track=' . $keywords);

    }
}

还有 cron 作业 * * * * * php /path/to/artisan schedule:run >> /dev/null 2>&1 时间表只是一个 $schedule->command('connect')->everyMinute();

【问题讨论】:

  • 您是否收到任何错误消息?
  • storage/logs/laravel.log?
  • 绝对清楚:(
  • 你安装了所有的依赖?类似"ext-hash": "*", "ext-json": "*", "lib-openssl": "*",

标签: php laravel twitter cron


【解决方案1】:

至于 cmets 和更改,您显然有两个不同的系统 16 和 15,安装了不同的软件和依赖项。不幸的是,没有简单的方法来解决这种故障,您必须检查所有内容,它仍然可能是未列出的 PHP 依赖项,甚至是操作系统依赖项和/或用户访问权限(您正在启动和终止进程,是工作还是异常结束?),但您的应用程序在 16 中运行良好,因此您可能会忘记 Laravel 和 Composer 并专注于 PHP 和 OS 层。

问题是,从这里开始,如果无法访问您的服务器,很难猜测,如果没有太大帮助,请见谅。

【讨论】:

    猜你喜欢
    • 2012-03-21
    • 1970-01-01
    • 2020-05-22
    • 1970-01-01
    • 1970-01-01
    • 2016-05-02
    • 1970-01-01
    • 1970-01-01
    • 2010-11-15
    相关资源
    最近更新 更多