我正在遵循 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/