假设yii项目路径为 /home/apps/
1. 创建文件 /home/apps/protected/commands/crons.php
2. 创建需要的配置文件 /home/apps/protected/config/console.php,配置需要的组件、数据库连接,日志等信息,格式类似主配置文件main.php
'mysql:host=xxxx;dbname=xxx', 'emulateprepare' => 'xxx', 'password' => 'xxx', 'charset' => 'utf8', 'tableprefix' => 'tbl_',
3. 在 /home/apps/protected/commands/ 下新建 testcommand 类,继承 cconsolecommand,在testcommand中,可以使用项目的配置信息和yii的各种方法
4. 创建定时任务
$ crontab -e
插入
1 * * * * /home/php/bin/php -f /home/apps/
即为每小时的第一分钟执行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...