Léo*_*oco 0 php cron laravel laravel-5.4
我使用Laravel 5.4,我想向用户发送通知上thursdays的8pm
假设我有
我应该如何设置 CRON JOB 以便他们都8pm在本地时间收到通知?。
我的服务器在纽约市
$schedule->command('sendNotifications')->dailyAt('20:00')->thursdays()
这个逻辑不能只用一个:$schedule->command('sendNotifications')命令和一些参数来完成。
第一步,如果尚未完成,请设置您的服务器并添加一个调用 Laravel artisan 命令的 Cron 作业:
* * * * * php /path-to-your-project/artisan schedule:run >> /dev/null 2>&1
第二步将您的计划命令更改为:
$schedule->command('sendNotifications')->everyFifteenMinutes();或
$schedule->command('sendNotifications')->everyThirtyMinutes();或
$schedule->command('sendNotifications')->hourly();
取决于您想要它的精确程度,因为某些时区有 30 或 45 分钟的偏移量,请参阅https://www.timeanddate.com/time/time-zones-interesting.html
现在,如果您的命令sendNotifications被执行,您必须在那里构建您的逻辑:
当然,您可以编写 40 多个不同的命令,每个时区一个,
并像这样使用调度程序:
$schedule->command('sendNotifications_1')
->timezone('America/Chicago')
->thursdays()
->dailyAt('20:00');
$schedule->command('sendNotifications_2')
->timezone('Europe/London')
->thursdays()
->dailyAt('20:00');
$schedule->command('sendNotifications_3')
->timezone('Asia/Tokyo')
->thursdays()
->dailyAt('20:00');
Run Code Online (Sandbox Code Playgroud)