A recent project needs to execute a controller on the server every 1 minutes, from the Internet to find a bit can be executed with a scheduled task, they have gone a lot of detours, Linux a little bit simpler, because the test server is Linux, the customer is using Windows Server 2016, So there are just two ways to use it.
Briefly explain my needs, I need the server timed to execute a URL, because I wrote a method in the controller, the entire URL with the TP framework, so a lot of online writing code can imitate, but not directly to use.
1. Linux
Crond is the Linux used to regularly execute the program commands, the specific use of Baidu or other detailed documentation can be viewed, here is not detailed instructions, only how to do a scheduled task through Crond.
There are 2 ways to add a task:
1. In the command line input: Crontab-e then add the corresponding task, Wq save the disk to exit.
2. Edit the/etc/crontab file directly, i.e. Vi/etc/crontab, add the corresponding task.
Such as:
* * * * * * sleep 1;/usr/bin/curl http://www.sxfewwa.com/Home/JPush/autoConfirm
Perform this link once every minute with curl
Hour of the week order
0-59 0-23 1-31 1-12 0-6 Command (value range, 0 for Sunday One a row corresponds to a task)
2. Windows Server
The first step, write your own method, PHP files, test words can be used test.php code as follows:
<?
$fp = fopen ("Test.txt", "A +");
Fwrite ($fp, Date ("Y-m-d h:i:s"). "Success has been successful!" \ n ");
Fclose ($FP);
?>
If it's a thinkphp, like me, the Controller method is the same as the other, and of course you can add a
function Test () {
$fp = fopen ("Test.txt", "A +");
Fwrite ($fp, Date ("Y-m-d h:i:s"). "Success has been successful!" \ n ");
Fclose ($FP);
}
Step Two: Write the bat file
Set link=http://www.sxfewwa.com/Home/JPush/autoConfirm
Start iexplore "%link%"
Ping-n 127.1>nul
taskkill/f/im "Iexplore.exe"
3, Windows A little more trouble, you need to create a task in the management tools, planning tasks,
The process can be viewed (http://blog.csdn.net/woshixuye/article/details/18050769) online and there are many similar articles.
thinkphp Executing PHP files regularly