Crontab cannot execute php solution

Source: Internet
Author: User
Crontab cannot execute php solution when using crontab to run the php program, how to debug each person has his/her own method. I also have a set of methods. let's take a look at how I solve the problem that crontab cannot execute the php program. I. is there any permission to execute the php file [root @ linuxcron] # ls-al | grep crontab cannot execute php? Solution
When you use crontab to run the php program, how can you debug it. I also have a set of methods. let's take a look at how I solve the problem that crontab cannot execute the php program.
I. is there any execution permission for the PHP file?
[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, it indicates that no execution permission is available, and of course it cannot be executed. If you do not know whether the Group of the user you log on to has permissions, simply add permissions to all groups. The method is as follows:
View copy print?
[Root @ linux cron] # chmod + x./del_redis.php
2. if you have the execution permission, you still cannot execute it.
The solution is as follows:
1. write the log (for example, error_log () function) in the php program. this is also required because crontab is periodically executed. if there is no log, how do you know the results of program execution. In this way, we can view the execution of crontab through log.
2. you can also directly output the execution result to a file in crontab. Then, view the execution status in the file. For example:
View copy print?
*/10 */usr/local/php/bin/php/var/www/cron/del_redis.php>/home/zhangy/cron.txt

3. execute php using crontab. apache and nginx are not supported. Therefore, $ _ SERVER and $ _ ENV variables cannot be used at all. So check if there are any such variables in the php code, if they are removed.

4. php relative paths
This problem is also the easiest to ignore because you have a mindset.
View copy print?
Include_once './mysql. php ';
When php code uses a relative path, it takes effect only when/usr/local/php/bin/php/var/www/cron/level_rank.php is in that directory. I have encountered this problem for at least two times, but I still cannot remember it.
The solution is as follows:
View copy print?
*/10 * cd/var/www/cron &/usr/local/php/bin/php/var/www/cron/level_rank.php
Or
Use absolute path in php code


For details, see
Http://blog.51yip.com/php/1346.html

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.