Laravel计划未运行

时间:2018-04-19 03:06:11

标签: php laravel cron

我遇到了Laravel调度程序的问题。它设置正确,命令是正确的,因为我可以从终端运行它,但它根本不起作用。据我所知,CRON工作是正确的,因为它确实显示sudo service cron status

但是php artisan schedule:run说什么都没有排队。我的Kernel.php如下

class Kernel extends ConsoleKernel
{
    /**
     * The Artisan commands provided by your application.
     *
     * @var array
     */
    protected $commands = [
      'App\Console\Commands\ResetBars',
      'App\Console\Commands\ResetUsers',
      'App\Console\Commands\UpdateBars',
    ];

    /**
     * Define the application's command schedule.
     *
     * @param  \Illuminate\Console\Scheduling\Schedule  $schedule
     * @return void
     */
    protected function schedule(Schedule $schedule)
    {
        $schedule->command('reset:bars')->hourlyAt(1);
        $schedule->command('reset:users')->daily();
        //$schedule->command('update:bars')->dailyAt('8:00');
    }

    /**
     * Register the commands for the application.
     *
     * @return void
     */
    protected function commands()
    {
        $this->load(__DIR__.'/Commands');

        require base_path('routes/console.php');
    }
}

我在命令的末尾有一个松弛的日志(我已经验证了它的工作)并且它没有每小时发送任何东西(1)因此它应该只是在8:01运行但它没有。

任何人都对为什么没有运行有任何想法?是排队还是不跑?

这是在cron标签

# Edit this file to introduce tasks to be run by cron.
#
# Each task to run has to be defined through a single line
# indicating with different fields when the task will be run
# and what command to run for the task
#
# To define the time you can provide concrete values for
# minute (m), hour (h), day of month (dom), month (mon),
# and day of week (dow) or use '*' in these fields (for 'any').#
# Notice that tasks will be started based on the cron's system
# daemon's notion of time and timezones.
#
# Output of the crontab jobs (including errors) is sent through
# email to the user the crontab file belongs to (unless redirected).
#
# For example, you can run a backup of all your user accounts
# at 5 a.m every week with:
# 0 5 * * 1 tar -zcf /var/backups/home.tgz /home/
#
# For more information see the manual pages of crontab(5) and cron(8)
#
# m h  dom mon dow   command
* * * * * php ~/var/www/BarhopAPI/artisan schedule:run >> /dev/null 2>&1

由于

  • 扎克

2 个答案:

答案 0 :(得分:1)

好的,所以我遵循的步骤,以确保我做对了

来自@devk的

crontab -l,非常感谢你

要向Laravel添加crontab作业,请安装crontab -e,然后在提示输入的类型(如果是第一次设置)时,点击2转到nano,然后粘贴以下内容星号

* * * * * php /var/www/Laravel/artisan schedule:run >> /dev/null 2>&1

显然将/var/www/Laravel替换为Laravel安装的路径

编辑:那不起作用。 Edit2:@devk帮助我修复它,需要删除~

答案 1 :(得分:0)

设置CRON作业时遇到相同的问题

我当时正在使用“ dailyAt()” 来运行CRON,实际上,我的CRON是 运行,但时区不是我自己的。请去检查一下 “ config / app.php” ,并检查您的时区(我刚刚更改了时区 到“亚洲/加尔各答”)

要测试您的CRON,请在您的schedule()方法内注释调度程序,然后添加新的调度( 此步骤将帮助您检查CRON是否正常工作

$schedule->command('jobexp:warning')->cron('* * * * *');

php artisan schedule:run

请确保您的CRON工作正常