Home  >  Article  >  Backend Development  >  Analysis of the reasons for failure of scheduled PHP scheduled tasks using crontab under Linux_PHP Tutorial

Analysis of the reasons for failure of scheduled PHP scheduled tasks using crontab under Linux_PHP Tutorial

WBOY
WBOYOriginal
2016-07-13 10:26:44875browse

Many people use crontab to implement PHP to execute scheduled tasks under Linux but fail to generate cache. This article analyzes the reasons for the failure of using crontab to implement scheduled PHP scheduled tasks under Linux.

Generally, our Linux regularly executes php code, for example:

*/5 * * * * /usr/local/php/bin/php /home/wwwroot/1.php

In fact, this can execute php code.

But why do many friends write a cache file in 1.php but it is not generated?

This involves the relative path issue of crontab executing php.

Note that there are files included in the executable file, such as:

include_once'./mysql.php'; 

When a relative path is used in the php code, you can only enter that directory,

Then execute /usr/local/php/bin/php /home/wwwroot/1.php to reference mysql.php to take effect.

The solution is as follows:

*/10 * * * * cd /home/wwwroot && /usr/local/php/bin/php /home/wwwroot/1.php

At the same time, the cache can be generated in /home/wwwroot. Special attention is needed here!

This is something that most of the so-called Linux scheduled execution of PHP has not mentioned, and it is also the most likely to cause misunderstandings.

Of course there are many methods, and you can also set environment variables and the like. This is just a simple method.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/824602.htmlTechArticleMany people use crontab to implement PHP to execute scheduled tasks under Linux but fail and cannot generate cache. This article analyzes the reasons for the failure of using crontab to implement scheduled PHP scheduled tasks under Linux...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn