简体   繁体   中英

Crontab and PHP script

I'm currently experiencing an issue that I just can't find it being solved online. I have tried two different Operating systems, and both have the same difficulty. One is Ubuntu, the other os OSx.

now the issue is, for this example, running a cron every minute to hit a .php file which in turn increments the count of a value found in a .txt file by 1.

At the beginning of the .php file I have:

#!/usr/bin/php

I have also tried adding the quiet tag at the end. Which didn't result in the cron working.

The cron command is as follows:

          • php /var/www/cron/index.php >/dev/null 2>&1

The output found inthe syslog under CRON is:

(user) CMD (php /var/www/cron/index.php >/dev/null 2>&1)

With no errors. If I run that command as it is given. The count in the .txt is incremented by 1. But there is nothing to show why the cron doesn't allow this to happen.

Sorry for the essay. Any suggestions would be greatly appreciated.

Just to leave an answer on this for future reference for others. Please check the files included into the php file being run by the Cron have absolute paths and not just paths local to the file itself.

Ie: do NOT have: include 'inc/test.php';

You would need to use for example: include '/var/www/cron/inc/test.php';

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM