Home  >  Article  >  Backend Development  >  Linux method code to solve PHP timer problem

Linux method code to solve PHP timer problem

小云云
小云云Original
2018-03-02 09:15:421457browse

This article mainly shares with you the method code of Linux to solve the PHP timer problem. PHP is often executed passively. The user sends an http request and the server executes it after receiving the request. It is difficult for him to take the initiative to do something. For languages ​​like PHP that do not have timers or have very weak timers, Linux scheduled tasks should be used decisively.

The idea is to plan tasks, execute CURL commands according to the set time, or send http requests. Since you like to be passive in PHP, let you be passive to the end.

1. Create scheduled tasks

[root@izbp17kcgwxvwveyk6c15dz ~]# crontab -e
crontab: installing new crontab
[root@izbp17kcgwxvwveyk6c15dz ~]# crontab -l
1 1 1 * *  /phpstudy/mycurl.sh
1,11,21,31,41,51 1,2,3,4 1 * *  /phpstudy/mycurldepot.sh
5,35 * * * *  /phpstudy/mycurlAutoCheck.sh
[root@izbp17kcgwxvwveyk6c15dz ~]#

Edit tasks crontab -e

View current tasks crontab -l

Detailed commands: Click to open the link

2.SH file CURL command

curl http://127.0.0.1/autocheck.php

3. Specific business logic

Executed in PHP

Related recommendations:

[Online help] About php timer problem

The above is the detailed content of Linux method code to solve PHP timer problem. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn