Crontab Can't execute PHP solution

Source: Internet
Author: User
Crontab Can't execute PHP workaround
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
[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:
View copy print?
[Root@linux cron]# chmod +x./del_redis.php
Second, if there is execution permission, still can not execute
Here's how to fix it:
1, in the PHP program to write log (for example: error_log () This function), which is also necessary, because crontab timed execution, if there is no log, how do you know the results of the program execution. This allows us to view the crontab execution through log.
2, you can also directly inside the crontab, will execute the result output a file. Then look at the implementation in this file. For example:
View copy print?
*/10 * * * */usr/local/php/bin/php/var/www/cron/del_redis.php >>/home/zhangy/cron.txt

3, with Crontab to execute PHP, is not to 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.

Relative path problem of 4,php
Because there is a mindset to do strange, this problem is also the most easily overlooked.
View copy print?
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:
View copy print?
*/10 * * * * Cd/var/www/cron &&/usr/local/php/bin/php/var/www/cron/level_rank.php
Or
Absolute path in PHP code


See details
Http://blog.51yip.com/php/1346.html
  • 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.