Home >Backend Development >PHP Tutorial >Summary of some methods for php to execute PHP scripts regularly_PHP Tutorial
This article summarizes some methods for regularly executing PHP scripts in PHP. There are methods in Linux, Windows, and PHP itself. Friends in need can refer to them.
Execute PHP script regularly under Linux
Execute PHP script
Method 1
If you want to execute a PHP script regularly, you can write it directly like this:
* /1 * * * * root -q /bin/local/php /path/to/your/php/script.php (execute script.php every minute)
Note that writing this way requires making PHP accessible Script file to execute. Under the command line, the directory where the script is located
chmod +x script.php
crontab+php-cgi executes the PHP script regularly
1. Create the requested script index in the web root directory. php
My file path (different paths depending on the installation path): /usr/local/webserver/htdosc/index.php
2. Create a crontab file
2.1 crontab -e
2.2 * * * * * /usr/local/webserver/php/bin/php-cgi -q /usr/local/webserver/htdosc/index.php
#Edit crond plan, request index.php every minute
is completed. After the above steps are completed, my computer can normally request index.php every minute
Notes:
1. /usr/local/webserver/php/ is my php installation path
2. php-cgi is the php parser (this is my understanding, but I always feel that I understand it wrong , hope you guys can correct me), some information is using ./bin/php, which is not available on my computer, so I use php-cgi, maybe the installation method is wrong.
3. -q is the quiet mode (seen in some materials) to run the php script
4. Some materials add #! to the first line of index.php /usr/ local/webserver/php/bin/php -q and add execution permissions to index.php. I didn't do this, and I could request index.php normally
Finally, I will introduce the implementation of a PHP scheduled execution task
The functions used ignore_user_abort(),set_time_limit(0),sleep ($interval)
You only need to run this code once and then close the browser.
The code is as follows
|
Copy code | ||||
do{
http://www.bkjia.com/PHPjc/444643.html