Reputation: 219
I have no idea whats going on. But I have a script that looks like this. Cron job refuses to run it:
include_once 'class_lib/mime_mail/mimeDecode.php';
include_once 'class_lib/Mail/IMAPv2.php';
include_once 'inc-functions.php';
include_once "$_SERVER[DOCUMENT_ROOT]/class_lib/DbFuctioneer.php";
$dbFuctioneer = new DbFuctioneer();
Everything works well when I remove:
$dbFuctioneer = new DbFuctioneer();
Even when DbFuctioneer() looks like this:
<?php
class DbFuctioneer {
function dbCountMatches( $count) {
return $count;
}
}
Does Cron have a problem with Classes in his Jobs?
Thank you for your time.
Kind regards,
Marius
It seems
$_SERVER['DOCUMENT_ROOT']
is empty when cron is running its job.
Why is that?
Upvotes: 0
Views: 208
Reputation: 449613
There is no $_SERVER["DOCUMENT_ROOT"]
present when you call the script from the command line.
That variable (along with many others like REQUEST_URI
, SCRIPT_NAME
, HTTP_HOST
....) is set by Apache, which is not running in your case.
You need to set the root directory manually.
To find out whether you are running in the context of a web site or from the command line, use php_sapi_name().
You could set $_SERVER["DOCUMENT_ROOT"]
manually when running on the command line, but I would rather use a completely new constant or variable to put the path into.
Upvotes: 3
Reputation: 23264
Do the following (run your script from the command line) and check the output is correct:
print("$_SERVER[DOCUMENT_ROOT]/class_lib/DbFuctioneer.php");
Most likely its broken.
Upvotes: 1