


Summary of various methods for timing PHP to execute scheduled tasks on a scheduled basis
Three ways to implement PHP scheduled execution
1. Windows scheduled tasks
2. Linux scripts
3. Let the web browser refresh regularly
Specific implementation
Windows scheduled tasks
PHP rarely runs on win servers, specific implementation I won’t go into details anymore. The principle of online implementation is probably to write a bat script, and then let the window task add and execute the bat script. For details, you can refer to: http://www.jb51.net/article/29134.htm
linux script implementation
The crontab command is mainly used here.
Usage method:
crontab filecrontab [ -u user ] [ -u user ] { -l | -r | -e }
Explanation:
crontab is used to allow the user to set the time at a fixed time Or for executing programs at fixed intervals
Use crontab to write a shell script, and then let PHP call the shell. This is using the characteristics of Linux and should not be considered the characteristics of PHP's own language. You can refer to: http://www.jb51.net/ article/29136.htm
PHP implements scheduled execution of scheduled tasks
Using PHP to refresh the browser requires solving several problems
PHP script execution time limit, the default is 30m Solution: set_time_limit(); or modify PHP.ini to set the max_execution_time time (Not recommended)
If the client browser is closed, the program may be forced to terminate. The solution: ignore_user_abort will still execute normally even if the page is closed.
If the program keeps executing, it is likely to consume a lot of resources. The solution is to use sleep to use the program to hibernate. After a while, then execute the
PHP scheduled execution code:
Copy the code The code is as follows:
ignore_user_abort();//Close the browser, and the PHP script can continue to execute.
set_time_limit(3000); // Through set_time_limit(0), the program can be executed without limit
$interval=5; // Run every 5s
//Method 1--Infinite loop
do{
echo 'Test' .time().'
';
sleep($interval);//Wait for 5s
}while(true);
//Method 2---sleep scheduled execution
require_once './curlClass. php';//Introduction file
$curl = new httpCurl();//Instantiation
$stime = $curl->getmicrotime();
for($i=0;$i<=10;$i++) {
echo 'test'.time().'
';
sleep($interval);//wait 5s
}
ob_flush();
flush();
$etime = $curl- >getmicrotime();
echo '
';
echo round(($etime-stime),4);//Program execution time
When testing, I found that this efficiency is not very high,
Summary:
Personally, I feel that PHP’s timed execution of tasks is not very efficient. It is recommended that the timed execution of tasks should be left to the shell. Comparison is the best way.
ps: The endless loop method seems to be a method often used by malicious attacks on websites

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











Sometimes, we need to leave the computer for a period of time to let it continue to download or allow certain programs, and want to shut down after the operation is completed. So how to set up a scheduled shutdown in win11? In fact, just use the shutdown command. How to set up a scheduled shutdown in win11: 1. First, right-click the start menu in the lower left corner and open "Run" 2. Then enter "shutdown-s-t7200" and press Enter to run. (7200 here is the scheduled shutdown time in seconds, 7200 is the shutdown after 2 hours) 3. In this way, we can complete the scheduled shutdown setting. 4. If you want to cancel the scheduled shutdown, just enter "shutdown-a" and press Enter. 5. After confirmation, you can cancel the scheduled shutdown.

With the popularity of Douyin, more and more users and companies have begun to pay attention to Douyin marketing. During the operation process, some users asked, will Douyin’s scheduled sending affect traffic? This article will discuss this issue and share a tutorial on how to set a timer to turn off playback on Douyin. 1. Will setting up scheduled sending on Douyin affect traffic? Douyin’s scheduled sending feature allows users to choose to automatically post at a specific time when creating a video. Regarding the impact of this feature on traffic, the official has not yet provided a clear explanation. Based on actual operational experience and analysis, it can be concluded that the impact of the scheduled sending function on traffic can be ignored. The core of Douyin traffic lies in the quality of video content and user interaction, not just the release time. Great content and engaging interactions are key to attracting users’ attention. when

Some friends don’t know that Win11 can also be set to automatically shut down. We can set the shutdown time in the running interface. Let’s take a look at the specific steps. Win11 scheduled shutdown: 1. First, we press and hold "win+r" on the keyboard to enter run. 2. Then we enter "at16:00shutdown-s" to set the 16-point shutdown, which can be set freely. 3. If you want to cancel, just enter "shutdown-a" to cancel the automatic shutdown.

As the leading video sharing platform in China, Kuaishou provides a stage for users to show themselves and share their lives. As user needs continue to increase, Kuaishou has continued to optimize and update, providing many practical functions, including the function of regularly publishing works. So, how to time the release of Kuaishou? This article will focus on this issue and the setting method of Kuaishou 24-hour live broadcast. 1. How to time Kuaishou releases? 1. Log in to Kuaishou App and click the "Create" button in the lower right corner of the homepage to enter the creation page. 2. Click the "Publish" button and find the "Scheduled Publish" button in the upper right corner of the work editing interface. 3. Enter the scheduled release setting interface, set the appropriate release time, and click the "Confirm" button. 4. The work will be automatically uploaded within the set time

Sometimes, I download an item, but I have to turn off the computer and fall asleep, but I also want to wait for the download to be completed before going to sleep. I think it would be great if I could turn on and off the computer at a scheduled time. Then I will share the win7 computer with you. How to set a timer to turn on and off the machine. How to set the scheduled power on and off of win7 computer 1. Click the menu bar icon in the lower left corner of the desktop, and then click the operation option in the pop-up interface or directly press win+R on the keyboard to form the keyboard shortcut. 2. Then type cmd and press Enter in the pop-up operation window. 3. Then a black cmd dialog box will open. In the current dialog box, type shutdown-f-s-t3600 and press Enter, and then a pop-up will appear in the lower right corner of the desktop.

As a popular social e-commerce platform, Xiaohongshu has attracted a large number of users and content creators. On the platform, publishing note works is an important way for users to interact with fans. So, can Xiaohongshu publish note-taking works on a regular basis? The answer is yes. 1. Can Xiaohongshu publish notes regularly? Xiaohongshu currently does not provide an official scheduled release function. However, users can publish notes on a scheduled basis through other methods. For example, users can prepare note content in advance and then use third-party tools or platform functions to publish it regularly. Although the Xiaohongshu platform itself does not have a scheduled publishing function, users can achieve this requirement through some techniques and tools. 2. Are there any practical tips for increasing the number of fans on a Xiaohongshu account? 1. Content quality

How to set a scheduled computer restart command. With the continuous development of technology, computers have become an indispensable part of our daily lives. However, not shutting down the computer for a long time can cause the system to run slowly or even cause various malfunctions. In order to maintain computer stability and improve efficiency, restarting the computer regularly is a very important step. So, how to set a scheduled computer restart command? First of all, in the Windows operating system, we can use the scheduled task tool to implement the function of restarting the computer regularly. Step 1: Open the scheduled task. First, click

MySQL and Shell Script: How to Implement Scheduled Data Cleaning Function Overview: When developing and maintaining database applications, it is often necessary to regularly clean expired or useless data in the database. The accumulation of these data will not only occupy the storage space of the database, but also affect the query performance of the database. This article will introduce how to implement scheduled data cleaning function through MySQL and Shell script. Creating a Cleaning Script First, we need to create a Shell script to perform data cleaning operations. Enter the following command in the terminal to create one
