When using the YII Framework, a yiic command tool is generated in the protected folder after the framework is structured. Here you can use the YII built-in command, first, you need to create a command php file under commands. The file name format is as follows: DemoCommand. php
The code is as follows:
The code is as follows: |
Copy code |
Class DemoCommand extends CConsoleCommand { // Number of processes Private $ thread = 10; Public function run ($ args) { $ Demos = $ this-> getDemo ($ args [0]); Echo "start ******************************** n ". date ('Y-m-d H: I: s '); Foreach ($ demos as $ demo) { $ This-> getTest ($ demo ); } Echo "running is completed ******************************* n ". date ('Y-m-d H: I: s '); } Public function getTest () { // The code you want to execute here is www.111cn.net. It can be any php code, including SQL. } Public function getDemo ($ index) { // The code you want to execute can be any php code, including SQL. Return $ index; } } |
I don't know if you have any questions. Have you noticed a variable $ args in the run method and called $ args [0] in the run method? $ args must be an array. But where does $ args come from? In this case, we need to pass the php command line parameters, for example, H: workspace> php test. php arg1 arg2.
I don't know much about this. Let's take a look at the parameters used to execute command commands in YII. It is a scheduled command execution program in Linux.
0 15, 11, 21 ** cd/file path/&/usr/local/php/bin/php yiic demo 0>/usr/home/test. log [the preceding number indicates that the command is executed at three o'clock P.M. on the first, 11th, and 21st of each month]
Run the command in protected of Yii:/usr/local/php/bin/php yiic create_excellenthall 0. Have you noticed the last 0? This is passed by $ args. You can replace it with any key value in the array.
The description should not be very professional. I hope it can help people who need it!