PHP require() not working with cronjob executed scripts
When I run a PHP script using a cronjob, a require() function halts the script without returning an error, but when I run the script directly, it executes without issue.
I'm using an absolute path to my include file: require('/home/userdir/public_html/path/to/file');
- I've compared get_include_path() and it returns the same location whether I'm running from cronjob or the script directly.
- I've tried using set_include_path to set the include path to the directory containing the file to include, but that hasn't worked.
- I've also tried using chdir() as some other threads suggest, but this hasn't worked either.
- I've tried using include() instead of require() in order to trigger a warning, but this produces the same problem.
- I've checked crontab to ensure that the conjob is being run by the same owner/group as the script and include file, but again, no errors being reported.
- I've used file_exists() to ensure that the include file I'm trying to require exists at the $abspath I'm providing to the function.
-
Welp, I managed to trace this to an issue with my WP login authentication during the init action hook. Had nothing to do with require. Solved! 0 -
How do you call php in cronjob? I suspect you should use full path to the PHP binary: /opt/cpanel/ea-php73/root/usr/bin/php -f /home/full/path/to/your/cron.file.php
it might be, that you simply run different PHP version and something does not get executed. You should turn on email notifications of the cron output to your email. And if that still does not work, should start debugging if cron and php run at all, for example running "php -v" in cron and sending yourself output.0 -
Glad to see you were able to resolve the issue though @hipwebdesign 0
Please sign in to leave a comment.
Comments
3 comments