Changing the return value in the switch. php file to 0 will automatically stop running. to execute it again, you must change the value to 1 and open the browser to execute it again.
If the value of $ switch is 1, even if ignore_user_abort () is not set, the loop cannot be stopped even if the browser is closed, and it is useless to delete the code file. the default value is 30 seconds, set_time_limit: Customize the execution time and restart the WEB service.
Below:
This method can implement the timing function, but once the code file is run, the process has been running, and I have not tested the consumption of server resources, however, some space vendors may not allow long periods of busy processes. if you have friends with VPS or servers, we recommend that you plan tasks on the servers to execute scripts on your website.
The following describes how to use Crontab in Linux.
For more information about how to use crontab, see: Linux scheduled task crontab.
1. use PHP to execute scripts in Crontab
Just like calling common shell scripts in Crontab (specific Crontab usage), PHP programs are used to call PHP scripts.
Execute myscript. php every hour as follows:
# Crontab-e
00 ***/usr/local/bin/php/home/web/3aj. php
/Usr/local/bin/php is the path of the PHP program.
2. use the URL in Crontab to execute the script
If your PHP script can be triggered through a URL, you can use lynx, curl, or wget to configure your Crontab.
The following example uses the Lynx text browser to access the URL and execute the PHP script hourly. the Lynx text browser opens the URL in dialog mode by default. However, as shown below, we use the-dump option in the lynx command line to convert URL output to standard output.
00 ***** lynx-dump http: // your URL/script. php
The following example uses the CURL access URL to execute the PHP script every 5 minutes. The Curl displays the output in the standard output by default. The "curl-o" option is used, you can also dump the script output to a temporary file.
*/5 */usr/bin/curl-o temp.txt http: // your URL/script. php
The following example uses the wget url to execute the PHP script every 10 minutes. The-q option indicates quiet mode, and "-O temp.txt" indicates that the output will be sent to a temporary file.
*/10 */usr/bin/wget-q-O temp.txt http: // your URL/script. php
Next we will introduce the implementation of php tasks in Windows:
1. create a new 3aj. php with the following content:
2. create a 3aj. bat file with the following content:
C: \ php \ php.exe-q D: \ web \ 3aj. php
3. create a WINDOWS scheduled task:
Start> Control Panel> Task Scheduler> Add Task Scheduler
Browse the folder and select the above 3aj. bat file
Set the time and password, and log on to WINDOWS to save it.
4. right-click the scheduled task and choose "run.
Article address:
Reprint at will ^ please include the address of this article!