Home >Backend Development >PHP Tutorial >Solution to crontab being unable to execute php
This article analyzes the solution to the problem that crontab cannot execute php. I would like to share it with you for your reference. The details are as follows:
When using crontab to run a PHP program, everyone has their own method on how to debug it. I also have a method. Let’s take a look at how I solved the problem of crontab not being able to execute the PHP program.
1. Does the php file have execution permission?
Copy the code The code is 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, it means there is no execution permission, and of course it cannot be executed. If you don’t know whether the group to which the user you are logging in has permissions, just add permissions to all groups. The method is as follows:
Copy the code The code is as follows:
[root@linux cron]# chmod +x ./del_redis.php
The solution is as follows :
1. Write logs in the PHP program (for example: the error_log() function). This is also necessary because crontab is executed regularly. If there is no log, how do you know the results of program execution. In this way, we can view the execution status of crontab through log.
2. You can also directly output the execution results to a file in crontab. Then check the execution status in this file. For example:
Copy the code The code is as follows:
*/10 * * * * /usr/local/php/bin/php /var/www/cron/del_redis.php >> /home/zhangy /cron.txt
4. The relative path problem of php
Because of the wrong mindset, this problem is also the easiest to ignore.
Copy the code The code is as follows:
include_once'./mysql.php';
The solution is as follows:
Copy the code The code is as follows:
*/10 * * * * cd /var/www/cron && /usr/local/php/bin/php /var/www/cron /level_rank.php
Readers who are interested in more PHP-related content can check out the special topics of this site: "Introduction Tutorial on PHP Basic Syntax" and "Introduction Tutorial on PHP Object-Oriented Programming"
I hope this article will be helpful to everyone in PHP programming.
The above introduces the solution to the problem that crontab cannot execute PHP, including the relevant content. I hope it will be helpful to friends who are interested in PHP tutorials.