Thinkphp executes php files regularly
Recently, a project needs to execute the controller every minute on the server. It can be executed with scheduled tasks from the Internet, and I have taken a lot of detours. Linux is a little simple, because the test server is linux, and the customer is using windows server 2016, so both methods are used.
Briefly explain my needs, I need the server to execute a URL regularly, because I have written the method in the controller, the entire URL uses the tp framework, so a lot of code written on the Internet can be imitated, but can not be used directly.
1 、 linux
Crond is a command that linux uses to execute the program on a regular basis. Specific usage can be done by Baidu or other detailed documents. There is no detailed explanation here, only how to do a scheduled task through crond.
There are 2 ways to add tasks:
1. Type: crontab-e on the command line and then add the corresponding task, and wq saves and exits.
two。 Edit the / etc/crontab file directly, that is, vi / etc/crontab, and add the appropriate tasks.
Such as:
* sleep 1; / usr/bin/curl http://www.sxfewwa.com/Home/JPush/autoConfirm
Execute this link in curl every other minute
Order for hours, days, months and weeks
0-59 0-23 1-31 11-120-6 command (value range: 0 indicates that a typical Sunday row corresponds to a task)
2 、 windows server
The first step is to write your own method, the php file, and test it with the following test.php code:
If you are using thinkphp, like me, the method in Controller is the same as the others, of course, you can add a
Function test () {
$fp = fopen ("test.txt", "a +")
Fwrite ($fp, date ("Y-m-d H:i:s"). "successful!\ n")
Fclose ($fp)
}
Step 2: write the bat file
Set link= http://www.sxfewwa.com/Home/JPush/autoConfirm
Start iexplore "link%"
Ping-n 80 127.1 > nul
Taskkill / f / im "iexplore.exe"
3. Windows is a little more troublesome. You need to create a task in "Management tools"-> "schedule tasks".
Process can be viewed (http://blog.csdn.net/woshixuye/article/details/18050769) there are many similar articles on the Internet.