Cause Analysis of task failure in PHP scheduled by crontab in linux _ PHP Tutorial

Source: Internet
Author: User
In linux, the cause of task failure in PHP scheduled by crontab is analyzed. In linux, the cause of the failure of the PHP scheduled task scheduled by crontab is analyzed. Many people use crontab in linux to execute scheduled PHP tasks, but use crontab in linux to analyze the causes of PHP scheduled tasks failure.

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.

Why does a scheduled PHP task fail when crontab is used in customized linux. Many people use crontab in linux to execute scheduled tasks in PHP,...

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.