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. locate
before 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