PHP require() not working with cronjob executed scripts

hipwebdesign

Registered
Nov 11, 2019
2
0
1
Bellingham, WA
cPanel Access Level
Website Owner
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.

This is on a GoDaddy Deluxe Linux Hosting with cPanel plan. I'm running PHP v7.3. Error reporting is on.

I'm about out of ideas, so any others are greatly appreciated!
 

anton_latvia

Well-Known Member
PartnerNOC
May 11, 2004
380
10
168
Latvia
cPanel Access Level
Root Administrator
How do you call php in cronjob? I suspect you should use full path to the PHP binary:
Code:
/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.
 
  • Like
Reactions: cPanelLauren