Use crontab in linux to analyze the cause of scheduled PHP task failure

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.