thinkphp scheduled execution of PHP files--windows System Task Scheduler

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.