Laravel 任務調度

來源:互聯網
上載者:User
通過伺服器定時任務 調用 laravel命令或方法

1.在app\Console\Commands 下建立定時任務所要進行的操作

建立命令: php artisan make:console test

$signature = “testCommand”; 這裡的簽名,在kernel.php中任務命令中也要用到;

2.在Kernel.php 中調用

protected $commands = [

‘App\Console\Commands\test’, #應用程式中所要調用的artisan集合

];

$schedule->command('testCommand')->everyMinute(); #這裡的testCommand與app\Console\Commands中的簽名要相同

注釋:也可以 $schedule->command(‘testCommand’)->cron(‘* * * * *’); 來設定時間

3.還需要在配置 /etc/crontab 檔案

          • root php /home/vagrant/Code/artisan schedule:run

      注釋:laravel文檔上有

          • php /path/to/artisan schedule:run 1>> /dev/null 2>&1

這裡的path 是項目的路徑 而不是檔案路徑!!!

Linux下的任務調度分為系統和使用者任務調度:

a.crontab -e 屬於使用者自訂,會被寫入到/var/spool/cron 目錄中,並且聲稱一個和使用者名稱一致的檔案,檔案內容就是編輯的定時指令碼

[可以進入到/var/spool/cron 查看使用者目錄]

使用者定期要執行的工作,比如使用者資料備份、定時寄件提醒等。

b.vim /etc/crontab 屬於系統層級的,系統周期性所要執行的工作,比如寫快取資料到硬碟、日誌清理等。

以上就介紹了Laravel 任務調度,包括了方面的內容,希望對PHP教程有興趣的朋友有所協助。

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.