This time I will bring you a detailed explanation of the steps to create a scheduled task through the console command in the yii framework. What are the precautions for creating a scheduled task through the console command in the yii framework. The following is a practical case, let’s take a look. one time.
Assume that the Yii project path is /home/apps/1, create the file /home/apps/protected/commands/crons.php
<?php $yii = '/home/apps/framework/yii.php'; require_once ($yii); $configFile = dirname (FILE).'/../config/console.php'; Yii::createConsoleApplication($configFile)->run();
<?php return array( 'basePath'=>dirname(FILE).DIRECTORY_SEPARATOR.'..', 'name'=>'Emergency', 'import'=>array( 'application.models.*', 'application.components.*', 'application.extensions.*', ), 'components'=>array( 'log'=>array( 'class'=>'CLogRouter', 'routes'=>array( array( 'class'=>'CFileLogRoute', 'levels'=>'info, warning, error', ), ), ), 'db'=>array( 'class'=>'application.extensions.PHPPDO.CPdoDbConnection', 'pdoClass' => 'PHPPDO', 'connectionString' => 'mysql:host=xxxx;dbname=xxx', 'emulatePrepare' => true, 'username' => 'xxx', 'password' => 'xxx', 'charset' => 'utf8', 'tablePrefix' => 'tbl_', ), ), 'params' => require('params.php'),);
<?php class TestCommand extends CConsoleCommand { public function run() { ... } }
$ crontab -e
The content is:
1 * * * * /home/php/bin/php -f /home /apps/protected/commands/crons.php Test & is to execute the contents of the TestCommand class in the first minute of every hour. Similarly, you can create other classes under /home/apps/protected/commands/ and use the command Execute.
Detailed explanation of the use case of volist tag in thinkphp
Detailed explanation of the steps for printing binary trees in Z-shaped order in PHP
thinkWhat are the precautions for using the volist tag in ajax in thinkphp
The above is the detailed content of Detailed explanation of the steps to create scheduled tasks through console commands in the Yii framework. For more information, please follow other related articles on the PHP Chinese website!