user979331
user979331

Reputation: 11851

Cron Job Error when running a PHP file

I am trying to run a php file via cron job, the file works fine when I run it manually, but when I run it in a cron job, I get this error:

Warning: include(classes/EmailAddressValidator.php): failed to open stream: No such file or directory in /var/www/onecent_dev/classes/MiscFunctions.php on line 3

Warning: include(): Failed opening 'classes/EmailAddressValidator.php' for inclusion (include_path='.:/usr/share/php:/usr/share/pear') in /var/www/onecent_dev/classes/MiscFunctions.php on line 3

MiscFunctions.php & EmailAddressValidator.php are both existing files and are in the right place, what gives?

Thanks

Upvotes: 2

Views: 3009

Answers (2)

Alex Howansky
Alex Howansky

Reputation: 53533

Looks like your include_path is resolving . to whatever cron happens to have the current directory set to, as opposed to the directory where your script is. Try editing your crontab to cd first:

0 * * * * cd /path/to/script && php script.php

Or provide the include_path explicitly:

0 * * * * php -d include_path=/path/to/script script.php

Upvotes: 11

Lyndsy Simon
Lyndsy Simon

Reputation: 5288

See this question: PHP: Require path does not work for cron job?

Your include_path doesn't contain the path of the script you're executing.

Upvotes: 0

Related Questions