Method of executing php scripts at a specified time under the linux system

  • 2020-05-17 07:28:32
  • OfStack

preface

In windows server regularly execute a program code is relatively simple, as long as it is ok to do regular tasks in the system, at present has just come into contact with the under linux timing task, it will be mentioned in a lot of company, and for my linux small white, is a big challenge, listen to the unit colleague said, linux regularly perform PHP script is very simple, linux using crontab tool system implementation plan task 1, ok, now share one can perform a successful php script, for your reference.

1. Add to line 1 of the PHP file that needs to be executed regularly


 view plain copy 
 
#! /bin/local/php -q 

Where /bin/local/php is the location of its own php.exe

2. Upload to regularly perform php file to a location, can pass/path/to/your/php/script php access to. And turn PHP into an executable script file. At the command line, the script resides in the directory


 view plain copy 
 
chmod +x script.php 

3. Open the edit crontab file


 view plain copy 
 
vi /etc/crontab 

Add in:


 view plain copy 
 
01 6 * * * root -q /bin/local/php /path/to/your/php/script.php 

This means that script.php is executed at 6:01 every day

Waiting time before execution can also try/bin/local/under Linux php path/to your/php/script php, if we can run a success, that is ok, then you can wait for the regular operation.

That's it. Note that script.php itself can't have relative paths or anything like that, but absolute paths in linux when needed.

Finally the test was successful.

conclusion

The above is the whole content of this article, I hope the content of this article to your study or work can bring 1 definite help, if you have questions you can leave a message to communicate.


Related articles: