thinkphp scheduled execution of PHP files--windows System Task Scheduler
The following ideas are implemented:
With WIN's "task" function to execute a bat file at timed time, the bat file invokes the Php.exe file, Php.exe can pass parameters specifying which class and method to execute
Here's how:
One, thinkphp turn on CLI support
1, TP support CLI Command mode exactly, the path of the manual is 13.7.4
If the other framework does not support the CLI, then only write the program directly, in fact, is to write the most basic process-oriented PHP code.
2, open the command under the entrance file, add a sentence
Define (' Mode_name ', ' CLI ');
The website generally also has the module which can be accessed through the webpage, so can create a new CLI entrance such as index_cli.php, so that other modules can also enter through the normal entrance. Some manuals written on the start CLI are defined by define ('think_mode ', ' CLI '); , which may be different versions, note this.
Ii. New BAT file creation
Create a new TXT file with the following three lines of content:
D:
CD D:\WORKSPACE\DZX2
Php.exe D:\workspace\dzx2\index_cli.php Sms/sendjob>c:\smslog.txt
This is: The current directory is moved to the D drive, the current directory is moved to the D:\workspace\dzx2 folder (my project portal file), the absolute path of the Php.exe space to enter the absolutely project CLI entry file, the following space + Parameter (I have added php.exe to the path variable of the system's environment variable, so only Php.exe is written)
Simple is: The current directory moved to the project portal file, the absolute path of the php.exe+ absolute path of the project portal file + parameters
TXT file to the bat suffix executable file, click Test to see if the method is executed
(You can write the bat file at the end of a Pause, to see if the error, or directly write ">c:\smslog.txt " bar output to import into a TXT file, Check the file after running to know whether or not to report errors
Iii. New tasks
Win under the Control Panel-"Management Program-" Task Scheduler Program
Right-click on Task Scheduler Library-New task
Must have permission to run an account
Trigger-"New selection frequency and other functions"
Action-"Create a new startup program below to find the bat file you wrote
Others can see for themselves
After setting up the task, click the program to run it, see the running time and results and do what your program did,
If you are wrong, note that the selected user permissions, the correct path, and the correct program are included.
So the general thing to do is to ensure that the program runs OK through the URL address, then, click the Bat file program to run OK, then the task is scheduled to run OK.
Other reference articles:
Timed task Behavior Extension
PHP automatically executes PHP files