linux - php cron job not running -
this question has answer here:
root@xx:/var/www/test# php /usr/bin/php
root@xx:/var/www/test# ls -la total 16 drwxrwxrwx 2 root root 4096 nov 14 09:37 . drwxrwxrwx 6 root root 4096 nov 13 15:51 .. -rwxrwxrwx 1 root root 153 nov 14 09:35 test.php
this test.php
file:
<?php $my_file = 'file.txt'; $handle = fopen($my_file, 'w') or die('cannot open file: '.$my_file); //implicitly creates file
and output of crontab -l
:
#this ok * * * * * touch /tmp/hello #this creates empty php_result.log * * * * * /usr/bin/php /var/www/test/test.php > /tmp/php_result.log
root@xx:/var/www/test# php -v php 5.4.34-0+deb7u1 (cli) (built: oct 20 2014 08:50:30)
the cron job not run, , problem php. if run file manually, works well.
php test.php
related question: why crontab not executing php script?.
you need use full paths in scripts. otherwise, cron
won't know file.
so instead of
$my_file = 'file.txt';
use
$my_file = '/path/to/file.txt';
probably getting file.txt
stored somewhere in /
.
note crontab
runs in limited environment, cannot assume regarding paths. that's why have provide full path of php
, etc.
from troubleshooting common issues cron jobs:
using relative paths. if cron job executing script of kind, must sure use absolute paths inside script. example, if script located @ /path/to/script.phpand you're trying open file called file.php in same directory, cannot use relative path such fopen(file.php). file must called absolute path, this: fopen(/path/to/file.php). because cron jobs not run directory in script located, paths must called specifically.
Comments
Post a Comment