php - Laravel 调度程序 - 在特定时间运行每月的特定日期

标签 php laravel-5.3

我想在每月的特定日期的特定时间运行任务。 现在我使用此代码在该月的 1 号和 15 日运行任务。

$schedule->command('payments:create')->daily()->when(function ()
    {
        $days = [1,15];
        $today = Carbon::today();

        return in_array($today->day, $days);
    });

有什么方法可以设置此任务在这些天的特定时间运行吗?

最佳答案

您可以通过多种方式实现它,以下两条:

$schedule->command('payments:create')->monthlyOn(1, '15:00');
$schedule->command('payments:create')->monthlyOn(15, '15:00');

如果您想强制任务在维护模式下运行,您可以使用evenInMaintenanceMode方法:

$schedule->command('payments:create')->monthlyOn(15, '15:00')->evenInMaintenanceMode();
$schedule->command('payments:create')->monthlyOn(1, '15:00')evenInMaintenanceMode();

在线用户安排事件每月运行两次的另一种方式(Laravel 5.4 及以上)

$schedule->command('payments:create')->twiceMonthly( 1, 15);

如果你想在特定时间运行,那么使用 ->at();方法。

$schedule->command('payments:create')->twiceMonthly( 1, 15)->at('13:00');// At 1 PM of every 1st and 15th of every month

另一种方法在每月1号和15号午夜执行Crontab

 $schedule->command('payments:create')->cron('0 5 1,15 * *');

关于php - Laravel 调度程序 - 在特定时间运行每月的特定日期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51398476/

相关文章:

php - 当我在 Laravel 中分页时找不到 MethodNotAllowedHttpException

php - 使用表单数据上传 Ajax 文件 Laravel 5.3

php - 缓慢的 vagrant box,如何改进?

php - jQuery AJAX 添加/编辑/删除操作可以被黑客攻击吗?

php - 如何解决这个 PHP 通知错误?

laravel - 方法列表不存在

php - Laravel 5.3 - htmlspecialchars() 期望参数 1 为字符串

javascript - Vuejs 2 使用 accounting.js

javascript - 如何隐藏Iframe src?

php - 表单未将值提交到 POST 数组 PHP