我正在关注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的预定工作时有类似的问题?
答案 0 :(得分: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');
现在只需将cronjob设置在服务器的contab文件中,如下所示。
* * * * * user php /var/www/html/projectfolder/artisan schedule:run >> /dev/null 2>&1
希望有所帮助......
答案 1 :(得分:0)
感谢Jobin的回复。 我发现bug存在于cron层。通过在Windows中创建crontab文件,我添加了linux拒绝正确解释的回车。 在记事本++或sublime文本中重新构建crontab文件解决了这个问题。