The realization of the idea is as follows: Through the win's "task" function to execute a bat file timed, BAT file calls the Php.exe file, Php.exe can pass parameters specify which class and method to execute
Here's how:
One, thinkphp turn on CLI support1, TP support CLI Command mode exactly, the path of the manual is 13.7.4if 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 sentencedefine (' 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 creationCreate a new TXT file with the following three lines of content:D:CD D:\workspace\dzx2Php.exe D:\workspace\dzx2\index_cli.php sms/sendjob>c:\smslog.txtThis 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 ISControl Panel--"Management Program-" Task Scheduler right-click Task Scheduler Library-"New task run account must have permission trigger-" newSelect frequency number and other functions-"new"Select Startup programFind the bat file you wrote below and see for yourself.
After setting up the task, click the program to run it, see the running time and results and do what your program did,
If there is a mistake, note that it contains
the selected user rights, the correct path, and the correct programSo 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