搜尋

首頁  >  問答  >  主體

laravel 定時任務 weekly

laravel中定時任務看到有weekly,

These methods may be combined with additional constraints to create even more finely tuned schedules that only run on certain days of the week. For example, to schedule a command to runrun week week on Monday: For example, to schedule a command to runrun week on day:#

$schedule->call(function () {
    // Runs once a week on Monday at 13:00...
})->weekly()->mondays()->at('13:00');

這裡的意思是必須要指定每週哪天具體時間的嗎?

還是可以直接用weekly?
如果直接用weekly的話又是這週哪天開始的呢?

伊谢尔伦伊谢尔伦2843 天前803

全部回覆(2)我來回復

  • PHP中文网

    PHP中文网2017-05-16 16:54:28

    Event.php檔案中:

    public function weekly()
    {
       return $this->cron('0 0 * * 0 *');
    }
    

    cron定時是 0 0 * * 0 *

    minute - 從0到59的整數
    hour - 從0到23的整數
    day - 從1到31的整數(必須是指定月份的有效日期)
    month - 從1到12的整數(或如Jan或Feb簡寫的月份)
    dayofweek - 從0到7的整數,0或7用來描述週日(或用Sun或Mon簡寫來表示)
    command - 需要執行的命令(可用as ls /proc >> /tmp /proc或執行自訂腳本的命令)

    所以weekly意思就是 每週日的0點0分執行。

    回覆
    0
  • PHP中文网

    PHP中文网2017-05-16 16:54:28

    1.weekly預設每週日的0點0分執行
    2.你可用 weeklyOn($day, $time = '0:0')
    3.就沒有這個問題了

    回覆
    0
  • 取消回覆