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, we regularly execute php code in linux, for example:
*/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 php Code uses relative paths,
Then run/usr/local/php/bin/php/home/wwwroot/1.php to reference mysql. php.
The solution is as follows:
*/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.