Crontab Unable to execute PHP workaround, crontabphp_php tutorial

Source: Internet
Author: User

Crontab Unable to execute PHP workaround, crontabphp

This paper analyzes the solution that crontab cannot execute PHP. Share to everyone for your reference, as follows:

When using crontab to run PHP program, how to debug, everyone has a method. I also have a set of methods to see how I solve the problem that crontab cannot execute PHP program.

One, PHP file has no execute permission
Copy the Code code as follows: [Root@linux cron]# ls-al |grep del

-rwxr-xr-x 1 zwh ftpgroup 494 10-20 16:42 del_redis.php
If there is no X, the description does not execute, and of course it does not. If you don't know if the group you're logged in with has permissions, just add permissions to all groups. Here's how:
Copy the Code code as follows: [Root@linux cron]# chmod +x./del_redis.php
Second, if there is enforcement authority, or can not execute

here's how to fix it:

1. Write the log in the PHP program (for example: error_log () This function), which is also necessary, because crontab timed execution, if there is no log, how do you know how the results of the program execution. This allows us to view the crontab execution through log.

2. You can also directly inside the crontab, the results of the execution output a file. Then look at the implementation in this file. For example:
Copy the Code code as follows: */10 * * * */usr/local/php/bin/php/var/www/cron/del_redis.php >>/home/zhangy/cron.txt
3. Use Crontab to execute PHP, do not go apache,nginx, so $_server,$_env such variables are not used at all. So check the PHP code to see if there are any such variables, if you have to take off.

4. Relative path problems with PHP

Because there is a mindset to do strange, this problem is also the most easily overlooked.
Copy the Code code as follows: Include_once './mysql.php ';
When you use a relative path in your PHP code, you only have to go into that directory to execute/usr/local/php/bin/php/var/www/cron/level_rank.php to take effect. I have encountered this problem at least two times, but I still can't remember it when I met him.

Here's how to fix it:
Copy the Code code as follows: */10 * * * * Cd/var/www/cron &&/usr/local/php/bin/php/var/www/cron/level_rank.php
or the absolute path in the PHP code

More readers interested in PHP related content can view this site topic: "PHP Basic Grammar Primer Tutorial" and "PHP Object-oriented Programming primer"

I hope this article is helpful to you in PHP programming.

Articles you may be interested in:

    • Implementing crontab code sharing in PHP
    • Analysis of the reasons for the failure of scheduled PHP tasks using crontab under Linux
    • Linux uses crontab to implement scheduled tasks for PHP execution
    • Parsing crontab PHP Auto-run method
    • How to use Linux crontab to execute PHP scripts in a timed manner true techarticle crontab cannot execute PHP solution, crontabphp This article analyzes the crontab can not execute PHP solution. Share to everyone for your reference, as follows: When running PHP with Crontab, ...

  • 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: 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.