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

Source: Internet
Author: User
Many people use crontab to implement PHP to perform timed tasks under Linux and fail to generate the cache. This paper analyzes the reasons of using crontab to realize scheduled PHP task failure in Linux.

Generally we Linux regularly execute PHP code such as:

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

In fact, this is possible to execute PHP code.

But why do many friends write in 1.php to generate a cache file that is not generated?

This involves crontab the relative path of PHP execution .

Note In the execution file, there are files that are included, such as:

When using a relative path in PHP code, you only have to go to that directory.

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

Here's how to fix it:

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

also this way the cache can be generated in/home/wwwroot. Special attention is needed here!

This is mostly written by the so-called Linux timed execution PHP is not mentioned, but also the most prone to misunderstanding.

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

http://www.bkjia.com/PHPjc/824602.html www.bkjia.com true http://www.bkjia.com/PHPjc/824602.html techarticle Many people use crontab to implement PHP to perform timed tasks under Linux and fail to generate the cache. In this paper, the use of Linux under the crontab implementation of scheduled PHP task failure reasons to do an analysis ...

  • Related Article

    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.