Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP include in a cron job

Tags:

php

cron

I'm trying to setup a PHP file as a cron job, where that PHP file includes other PHP files.

The file itself is located at /var/www/vhosts/domain.com/httpdocs/app/protected/classes/cron/runner.php

The include file is at /var/www/vhosts/domain.com/httpdocs/app/protected/config.php

How do I include that config file from runner.php? I tried doing require_once('../../config.php') but it said the file didn't exist.. I presume the cron runs PHP from a different location or something.

The cron job is the following..

/usr/bin/php -q /var/www/vhosts/domain.com/httpdocs/app/protected/classes/cron/runner.php

Any thoughts?

like image 484
RichW Avatar asked Feb 19 '11 22:02

RichW


1 Answers

Your cron should change the working directory before running PHP:

cd /var/www/vhosts/domain.com/httpdocs/app/protected/classes/cron/ && /usr/bin/php -q runner.php

Note that if the directory does not exist, PHP will not run runner.php.

like image 148
Lekensteyn Avatar answered Sep 20 '22 21:09

Lekensteyn