【问题标题】:running cron job in laravel 5在 laravel 5 中运行 cron 作业
【发布时间】:2015-09-17 18:21:18
【问题描述】:

我已将我的命令注册为php artisan run:process,它看起来像

  class queuedTransaction extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'run:process';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Running the queued transaction.';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle(){
       DB::table('transfers')->truncate();
    }

}

这是我的kernel.php

class Kernel extends ConsoleKernel
{

    protected $commands = [
        \App\Console\Commands\Inspire::class,
        \App\Console\Commands\queuedTransaction::class,

    ];


    protected function schedule(Schedule $schedule)
    {


      $schedule->command('run:process')->everyMinute();

    }
}

现在我想每分钟运行一次php artisan run:process 并截断transfers 表,但cron 现在不起作用。为了确保command 本身是否正常工作,我将command 放入我的routes 并调用它,它的截断表含义命令正在发挥作用。

【问题讨论】:

    标签: php cron laravel-5


    【解决方案1】:

    在 Kernel.php 中,您的命令应包含在:

    /**                                                                                                             
     * The Artisan commands provided by your application.
     *
     * @var array
     */
     protected $commands = [
         MyCommand::class
     ];
    

    您也可以删除 Inspire :)

    【讨论】:

    • 那么运行 cronjob 的用户是什么?无法写入日志可能会阻止执行。因此,如果 Apache 在 www-data 下运行,但您的登录用户正在运行 cronjob,则可能会抛出它。检查 /var/log/syslog(如果适用)以查看 cronjob 是否运行正常,或者是否立即显示错误。
    • 我已经添加了我的命令,例如 /usr/local/bin/php /home/smsnep5/public_html/projectname/artisan schedule:run schedule:run >> /dev/null 2>&1 ,但它没有任何好处。但支持团队说 cron 作业正在运行
    • PS 我也更新了我的问题。请看一下:)
    猜你喜欢
    • 1970-01-01
    • 2011-03-20
    • 2013-11-27
    • 2018-12-09
    • 2014-07-22
    • 2018-06-25
    • 2017-11-03
    • 1970-01-01
    • 2016-03-06
    相关资源
    最近更新 更多