Solution to crontab being unable to execute php, crontabphp_PHP tutorial

WBOY
Release: 2016-07-12 08:59:55
Original
901 people have browsed it

The solution to the problem that crontab cannot execute php, crontabphp

This article analyzes the solution to the problem that crontab cannot execute php. Share it with everyone for your reference, the details are as follows:

When using crontab to run PHP programs, everyone has their own way of debugging. I also have a method. Let’s take a look at how I solved the problem that crontab cannot execute PHP programs.

1. Does the php file have execution permissions
Copy 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 that 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. Here’s how:
Copy the code The code is as follows: [root@linux cron]# chmod x ./del_redis.php
2. If you have execution permission, it still cannot be executed

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 code The code is as follows:*/10 * * * * /usr/local/php/bin/php /var/www/cron/del_redis.php >> /home /zhangy/cron.txt
3. Using crontab to execute PHP does not require apache or nginx, so variables such as $_SERVER and $_ENV cannot be used at all. So check if there are such variables in the php code and remove them if so.

4. PHP relative path problem

Because of the fixed mindset, this problem is also the easiest to ignore.
Copy the code The code is as follows: include_once'./mysql.php';
When a relative path is used in the PHP code, it will only take effect after entering that directory and executing /usr/local/php/bin/php /var/www/cron/level_rank.php. I've encountered this problem at least twice, but I still can't remember it when I encounter it again.

The solution is as follows:
Copy code The code is as follows:*/10 * * * * cd /var/www/cron && /usr/local/php/bin/php /var/www/cron/level_rank .php
Or use absolute path

in php code

Readers who are interested in more PHP-related content can check out the special topics on 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.

Articles you may be interested in:

  • Sharing of crontab code in PHP
  • Analysis of the reasons for failure of using crontab to implement scheduled PHP scheduled tasks under Linux
  • Linux uses crontab to implement PHP execution scheduled scheduled tasks
  • How to parse crontab PHP automatic operation
  • How to use Linux's Crontab to regularly execute PHP scripts

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1095686.htmlTechArticleThe solution to the problem that crontab cannot execute php, crontabphp This article analyzes the solution to the problem that crontab cannot execute php. Share it with everyone for your reference, the details are as follows: When using crontab to run php programs,...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!