I use $_SERVER['DOCUMENT_ROOT']."/lib/sft_required.php"; to include the 'sft_required' file in a PHP script. When I run this file using browser, it works fine but when I run this as a cron job job, it does not work. It seems that the file is not included when we run the script through cron.
views:
639answers:
4
+4
A:
$_SERVER
cannot be expected to contain any of the normal values when a PHP script is run using the CLI interpreter. Either put the path in an environment variable, or pass it to the script as a command line argument.
Ignacio Vazquez-Abrams
2010-01-20 10:21:21
+3
A:
Assuming you are running the script directly through cron (as opposed to from a web server accessed by an HTTP request triggered by a cronjob (e.g. by cron running wget)), then of course it doesn't work.
There is no server, so $_SERVER
is not set.
David Dorward
2010-01-20 10:22:09
+1
A:
Reading the documentation should help. Using PHP from the command line
Alex
2010-01-20 10:23:52
+2
A:
you could populate the $_SERVER['DOCUMENT_ROOT'] on your own
$_SERVER['DOCUMENT_ROOT'] = dirname(__FILE__);
if the cron file is in document root
$_SERVER['DOCUMENT_ROOT'] = dirname(dirname(__FILE__));
if the cron file is one directory above the document root
solomongaby
2010-01-20 10:54:22