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

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

WBOY
Release: 2016-07-13 10:24:07
Original
908 people have browsed it

Analysis of the reasons for the failure of crontab scheduled PHP scheduled tasks under Linux

The reasons for the failure of using crontab to implement scheduled PHP scheduled tasks under Linux.

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 Linux regularly executes php code, for example:
*/5 * * * * /usr/local/php/bin/php /home/wwwroot/1.php
In fact, this can be executed 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 include files in the execution file, such as:
include_once'./mysql.php';

When using a relative path in the php code, you can only enter that directory, www.jbxue.com
Then execute /usr/local/php/bin/php /home/wwwroot/1.php Only by quoting mysql.php can it take effect.
Solution:
*/10 * * * * cd /home/wwwroot && /usr/local/php/bin/php /home/wwwroot/1.php
At the same time, the cache can be generated in this way /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/827212.htmlTechArticle Analysis of the reasons for the failure of crontab scheduled PHP scheduled tasks under Linux under Linux. Many people use crontab to implement PHP to perform scheduled tasks under Linux...
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template