Home>Article>Backend Development> How does PHP use the server to implement scheduled tasks?

How does PHP use the server to implement scheduled tasks?

慕斯
慕斯 forward
2021-06-21 10:02:45 3126browse

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.

How does PHP use the server to implement scheduled tasks?

Use the server to implement simple scheduled tasks, Windows scheduled tasks, Linux cron, suitable for certain characteristics every day Time execution

1. Scheduled access to the specified url under windows

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

2.Request url under Linux

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~23

The third column means date 1~ 31

The 4th column indicates the month 1~12

The 5th column identifies the week 0~6

Recommended learning:

php video tutorial

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!

Statement:
This article is reproduced at:csdn.net. If there is any infringement, please contact admin@php.cn delete