【问题标题】:Cron won't run Laravel scheduled jobsCron 不会运行 Laravel 计划的作业
【发布时间】:2016-03-06 02:06:30
【问题描述】:

我正在关注 Laravel 的计划作业基本教程,直接使用文档中的 Kernel.php 文件。

我的 crontab 文件是:

* * * * * date >> CRONTRACK.txt
* * * * * /usr/bin/php /home/vagrant/Code/sample/artisan schedule:run >> /home/vagrant/Code/laravel_cron_output.txt

cron 正在运行。我每分钟都会在 CRONTRACK.txt 中获得一个新的日期时间条目。 在终端中运行此命令也可以:

/usr/bin/php /home/vagrant/Code/sample/artisan schedule:run >> /home/vagrant/Code/laravel_cron_output.txt

有没有人在使用 cron 作业来运行 Laravel 的预定作业时遇到过类似的问题?

【问题讨论】:

    标签: php linux laravel cron


    【解决方案1】:

    试试这个,

    要设置作业调度,您可以使用kernel.php 为每个任务创建自定义命令,下面显示了从队列表发送短信的示例。

    在内核文件中将命令添加到数组中。

    protected $commands = [
            \App\Console\Commands\Inspire::class,
            \App\Console\Commands\SmsProcess::class,
        ];
    

    在命令中创建一个类SmsProcess,如下所示。

    class SmsProcess extends Command {
        /**
         * The name and signature of the console command.
         *
         * @var string
         */
        protected $signature = 'smsprocess';
    
        /**
         * The console command description.
         *
         * @var string
         */
        protected $description = 'Process the sms queue';
    
        /**
         * Execute the console command.
         *
         * @return mixed
         */
        public function handle() {
         //you cron job code here
        }
    }
    

    然后在Kernel.php 文件中设置您的首选时间,如下所示,在schedule() 中

    $schedule->command('smsprocess')
                ->everyMinute()
                ->sendOutputTo('storage/logs/smsprocess.log');
    

    现在只需在服务器的 contab 文件中设置 cronjob,如下所示。

    * *  * * *   user   php /var/www/html/projectfolder/artisan schedule:run >> /dev/null 2>&1
    

    希望对你有帮助..

    【讨论】:

      【解决方案2】:

      感谢乔宾的回复。 我发现这个错误在 cron 层上。通过在 Windows 中制作 crontab 文件,我添加了 linux 拒绝正确解释的回车。 在 notepad++ 或 sublime 文本中重新制作 crontab 文件解决了该问题。

      【讨论】:

        猜你喜欢
        • 2010-09-12
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-07-17
        • 2019-07-22
        • 1970-01-01
        相关资源
        最近更新 更多