Cause Analysis of task failure in PHP scheduled by crontab in linux
In linux, crontab is used to implement the reason why the scheduled PHP task fails.
Many users use crontab in linux to execute scheduled tasks in PHP but fail to generate a cache. In this article, we will analyze the causes of scheduled PHP task failure using crontab in linux.
In general, linux regularly executes php Code such:
*/5 */usr/local/php/bin/php/home/wwwroot/1.php
In fact, php code can be executed.
But why do many of my friends write in 1.php to generate a cache file?
This involves the relative path of crontab to execute php.
Note that the execution file contains files, such:
Include_once './mysql. php ';
When the php Code uses a relative path, it only enters the directory www.jbxue.com.
Then run/usr/local/php/bin/php/home/wwwroot/1.php to reference mysql. php.
Solution:
*/10 * cd/home/wwwroot &/usr/local/php/bin/php/home/wwwroot/1.php
In this way, the cache can be generated at/home/wwwroot. Special attention is required here!
This is not mentioned in most of the so-called linux scheduled execution php, and it is also the most prone to misunderstandings.
Of course, there are still many methods. You can also set environment variables and so on. This is just a simple method.