Linux executes PHP scripts on a regular basis
Execute PHP Script
Method 1
If you want to execute a PHP script on a regular basis, you can write it directly:
*/1 * * * * * root-q/bin/local/php/path/to/your/php/script.php (script.php per minute)
Note that you need to turn PHP into an executable script file. At the command line, the directory where the script resides
chmod +x script.php
crontab+php-cgi Execute PHP scripts regularly
1. Create the requested script in the Web root directory index.php
My file path (different paths depending on the installation path):/usr/local/webserver/htdosc/index.php
2. Create crontab files
2.1 Crontab-e
2.2 * * * * * */usr/local/webserver/php/bin/php-cgi-q/usr/local/webserver/htdosc/index.php
#编辑crond计划, request index.php per minute
Completed, the above steps are completed, in my computer can be normal per minute request index.php
Precautions:
One./usr/local/webserver/php/is my PHP installation path
Two. php-cgi is the PHP parser (my understanding is that, I always feel that I understand the wrong, I hope the prawns are correct), some information is used./bin/php, I can not on the computer, so with php-cgi, may install the wrong way.
Three. Q is quiet mode (see in some data) run PHP script
Four. Some of the information is to add #! to the first line in index.php /usr/local/webserver/php/bin/php-q, and add execute permissions to index.php. I didn't do it, and I was able to request index.php.
Finally, the implementation of a PHP timed execution task is introduced
Functions used Ignore_user_abort (), Set_time_limit (0), Sleep ($interval)
This code closes the browser as soon as it is run once.
code is as follows |
copy code |
Ignore_ User_abort ()//Turn off the browser, the PHP script can also continue to execute. Set_time_limit (0);//Through Set_time_limit (0) allows the program to execute indefinitely $interval =60*30;//run do{ every half hour // Here is the code you want to execute &NBSP sleep ($interval);/wait 5 minutes }while (true); |