The PHP task in Ubuntu-linux scheduled task crontab cannot be executed, for possible reasons

Source: Internet
Author: User
Wait for the executed test.php script, which can be executed on the local environment, manually execute PHP test.php on Linux can also execute

$name='./log/20161025.txt';if(file_exists($name)){    file_put_contents($name, '定时任务开始了');}

Perform crontab-e edit timed tasks

My attempt:

    • Executive Ps-ef | grep Cron, see the scheduled task process, you can see a process, that is, the scheduled task is running, so there is no scheduled task does not open the issue

    • Perform/usr/sbin/service cron Restart, restart scheduled Tasks, no records in Cron.log, no content in 20161025.txt

    • Execute CHOMD +x test.php add permission, no effect

    • Execute which PHP, return/usr/bin/php PHP path yes

Temporarily can not find the probable cause, seek the master idea

Add:
The final test of a scheduled task can be performed

$name=__DIR__.'/log/20161025.txt';if(file_exists($name)){    file_put_contents($name,date('Y-m-d H:i:s',time())."\r\n",FILE_APPEND);}

Print the current time with the script, which is performed once per minute

Reply content:

Wait for the executed test.php script, which can be executed on the local environment, manually execute PHP test.php on Linux can also execute

$name='./log/20161025.txt';if(file_exists($name)){    file_put_contents($name, '定时任务开始了');}

Perform crontab-e edit timed tasks

My attempt:

    • Executive Ps-ef | grep Cron, see the scheduled task process, you can see a process, that is, the scheduled task is running, so there is no scheduled task does not open the issue

    • Perform/usr/sbin/service cron Restart, restart scheduled Tasks, no records in Cron.log, no content in 20161025.txt

    • Execute CHOMD +x test.php add permission, no effect

    • Execute which PHP, return/usr/bin/php PHP path yes

Temporarily can not find the probable cause, seek the master idea

Add:
The final test of a scheduled task can be performed

$name=__DIR__.'/log/20161025.txt';if(file_exists($name)){    file_put_contents($name,date('Y-m-d H:i:s',time())."\r\n",FILE_APPEND);}

Print the current time with the script, which is performed once per minute

The PHP path is correct, but the working directory is not the directory where your PHP files are when you start the scheduled task, so your code needs to be changed.

$name=__DIR__.'/log/20161025.txt';if(file_exists($name)){    file_put_contents($name, '定时任务开始了');}

The sense is that the path is not correct, the relative address in the PHP script to the absolute path to try

PHP path Yes, wrong in the PHP code, some of the path, in the command line program, try to avoid the use of dependent things, such as relative directory,
That's your fault. In the relative directory, you start crontab to execute your PHP script before you execute it manually, and you know where the error is.
Print out your relative path. Must not be the path you imagined.

You can locate 20161025.txt , see if the file is generated. locatebefore the first updatedb .

Determine your permissions issues perform the following crontab-l determine that you have successfully added a scheduled task

[DongYao$ 19:28]➞ $crontab -l* * * * * /bin/echo `date` >> /var/log/test.logYou have mail in /var/mail/DongYao[DongYao$ 19:39]➞ $[root$ 19:37]➞ $tail -f /var/log/test.log Mon Oct 24 19:38:00 CST 2016Mon Oct 24 19:39:00 CST 2016
  • 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.