CodeIgniter Cron

當使用CodeIgniter開發web時,如需要用到cron排程定時去執行某php功能時,Cron job bootstrapper提供cron.php,透過這隻cron.php可以很簡單的在console下運作 CodeIgniter 所開發的功能。

準備

File:cron-1.1.zip

設置

將解壓縮後的cron.php放置專案目錄裡,並給予執行權限

1
chmod +x cron.php

修改

修改cron.php

1
define('CRON_CI_INDEX', '專案目錄的index.php');   // Your CodeIgniter main index.php file

運行

1
./cron.php --run=/controller/method

參數

1
2
3
4
5
6
7
8
9
10
11
--run=/controller/method
指定要執行的 /controller/method
 
--show-output
顯示執行結果於console
 
--log-file=logfile
設置執行後log檔位置
 
--time-limit=N
於幾秒後停止運作

參考資料

Related Posts with Thumbnails

相關文章

發表迴響

您的電子郵件位址並不會被公開。 必要欄位標記為 *

*

您可以使用這些 HTML 標籤與屬性: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>