假設Yii項目路徑為 /home/apps/
1. 建立檔案 /home/apps/protected/commands/crons.php
= '/home/apps/framework/yii.php'( = ().'/../config/console.php'::createConsoleApplication()->run();
2. 建立需要的設定檔 /home/apps/protected/config/console.php,配置需要的組件、資料庫連接,日誌等資訊,格式類似主設定檔main.php
'basePath'=>().DIRECTORY_SEPARATOR.'..', 'name'=>'Emergency', 'import'=>'application.models.*', 'application.components.*', 'application.extensions.*',, 'components'=>'log'=>'class'=>'CLogRouter', 'routes'=>'class'=>'CFileLogRoute', 'levels'=>'info, warning, error',,,, 'db'=>'class'=>'application.extensions.PHPPDO.CPdoDbConnection', 'pdoClass' => 'PHPPDO', 'connectionString' => 'mysql:host=xxxx;dbname=xxx', 'emulatePrepare' => , 'username' => 'xxx', 'password' => 'xxx', 'charset' => 'utf8', 'tablePrefix' => 'tbl_',,, 'params' => ('params.php'),
3. 在 /home/apps/protected/commands/ 下建立 TestCommand 類,繼承 CConsoleCommand,在TestCommand中,可以使用項目的配置資訊和Yii的各種方法
TestCommand ...
4. 建立定時任務
$ crontab -e
插入
1 * * * * /home/php/bin/php -f /home/apps//commands/crons.php Test &
即為每小時的第一分鐘執行TestCommand類中的內容,類似的可以在/home/apps/protected/commands/下建立其他類,使用命令列執行。
http://www.bkjia.com/PHPjc/749285.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/749285.htmlTechArticle假設Yii項目路徑為 /home/apps/ 1. 建立檔案/home/apps/protected/commands/crons.php ? = '/home/apps/framework/yii.php' ( = ( ).'/../config/console.php' ::createConsoleAppli...