This article will introduce to you how PHP uses the server to implement scheduled tasks? It has certain reference value. Friends in need can refer to it. I hope it will be helpful to everyone.
Use the server to implement simple scheduled tasks, Windows scheduled tasks, Linux cron, suitable for certain characteristics every day Time execution
Use a scheduled task to execute the auto.php file under windows, and use curl to request the specified interface in the auto.php file The code to implement
auto.php is as follows
function doCurlGetRequest($timeout = 5){ $url = 'http://127.0.0.1:81/index.php?s=/Admin/Index/dayBonus.html'; $con = curl_init((string)$url); curl_setopt($con, CURLOPT_HEADER, false); curl_setopt($con, CURLOPT_RETURNTRANSFER,true); curl_setopt($con, CURLOPT_TIMEOUT, (int)$timeout); return curl_exec($con); } $result = doCurlGetRequest(); var_dump( $result); die;
The new bat file command is as follows
C:\phpStudy\PHPTutorial\php\php-7.2.1-nts\php.exe -q C:\zx\auto.php
php path:
C:\phpStudy \PHPTutorial\php\php-7.2.1-nts\php.exe
auto.php path: C:\zx\auto.php
window scheduled task
Use CronTab to execute regularly on Linux
Execute crontab -e
Enter editing mode to add a line
* * * * curl https://www.aaa.com/aaa.php
The first part is the time, and the latter part is the operation content.
30 * * * *
30 is executed when the number of minutes per hour is 30.
The time parameter consists of the following parts
Time, day, month and week
##The first column indicates minutes 1 to 59. Each minute uses Or */1 means, /n means every n minutes, for example */8 means every 8 minutes The second column means hour 0~23The third column means date 1~ 31The 4th column indicates the month 1~12The 5th column identifies the week 0~6Recommended learning:
The above is the detailed content of How does PHP use the server to implement scheduled tasks?. For more information, please follow other related articles on the PHP Chinese website!