我需要每2周或14天运行laravel cron。但没有找到任何解决方案。我也在laravel文档https://laravel.com/docs/5.5/scheduling上搜索 ,发现了这个选项
->weekly();
Run Code Online (Sandbox Code Playgroud)
但是它每周运行一次。我也在搜索其他选项,发现此 Laravel Schedule任务每月运行10天, 但仅在每月的前10天运行
$schedule->command('log:test')->cron('0 0 1-10 * *');
Run Code Online (Sandbox Code Playgroud)
如果您有任何解决方案,请提前帮助我。
小智 6
$schedule->command('command_name')->weekly()->mondays()
->when(function () {
return date('W') % 2;
})->at("13:38");
Run Code Online (Sandbox Code Playgroud)
函数将每隔两周返回 1,因此该命令将每两周调用一次。
小智 0
$schedule->command('log:test')->cron('0 0 */14 * *');
Run Code Online (Sandbox Code Playgroud)
2017-09-15 00:00:00
2017-09-29 00:00:00
2017-10-01 00:00:00
2017-10-15 00:00:00
2017-10-29 00:00:00
或者你可以运行你的自定义
$schedule->command('log:test')->weekly()->when(function () {
return ((Carbon::now()->day % 2) === 1); //bool only for example
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1213 次 |
| 最近记录: |