PHP Cron Job not Including
Posted on 2011-03-09
I have a php scrip that works fine on the web
The first part of that script includes another set of files (which includes even more etc)
include $_SERVER['DOCUMENT_ROOT'] . "/myinclude.php";
. . .
However when I run this through cron
It fails with this message
<b>Warning</b>: include(/myinclude.php) [<a href='function.include'>function.include</a>]: failed to open stream: No such file or directory in <b>/home/mysite/public_html/somescript.php</b> on line <b>2</b><br />
And other error messages related to the fact that it can't connect to the db etc as all the connection data is in the myinclude.php file.
Having done some reading around this it seems that the cron jobs run from a different server / instance / something than the web so $_SERVER['DOCUMENT_ROOT'] doesn't work in the same way.
How do I get around this? The server is on third party hosting / cpanel so I have limited access to command line and php.ini etc files.