Home>Article>Backend Development> Detailed explanation of the steps to create scheduled tasks through console commands in the Yii framework
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 theprecautions 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
run();2, create the required
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'),);3. Create a new TestCommand class under /home/apps/protected/commands/ and inherit CConsoleCommand. In TestCommand, you can use the project's configuration information and Yii's various methods.
4, create a scheduled task$ crontab -e
For the usage of crontab, please refer to: crontab command basics and examples Some examples of crontab commands Detailed explanation of linux installation crontab crontab study notes Learn the crontab command to set up scheduled tasks in Linux Crontab command format and examples Linux scheduled task setting crontab learning Good crontab tutorial I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other related articles on the PHP Chinese website! Recommended reading:
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!