php - Cron 不会运行 Laravel 计划的作业

标签 php linux laravel cron

我正在遵循 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 的计划作业时遇到过类似的问题?

最佳答案

试试这个,

为了设置作业调度,您可以使用 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

希望对你有帮助..

关于php - Cron 不会运行 Laravel 计划的作业,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34032467/

相关文章:

c++ - 如何在 C++ 中运行另一个应用程序并与之通信,跨平台

c++ - 如何在 C++ 中找到 ELF 二进制文件所需的动态库?

mysql - 通过 eloquent 在 Laravel 中更新文件夹计数级联删除

php - 使用 php-ews 创建定期日历事件

php - 将 find() 与多个过滤器一起使用 Fat Free Framework

linux - 检查两个目录是否在haskell中的同一文件系统上

php - Laravel 中如何连接两个表?

php - Laravel DB::statement 无法为涉及列表达式的查询正确准备值

php - 是否可以使用 assetic 和 twig 创建 Assets 的条件路径?

PHP MySQLi - 插入或更新后 insert_id 0 - 我应该先阅读吗?