0
votes

The cron job process works, but it doesn't read global variables like $ _SERVER in php.

Cron Job Code:

/usr/local/bin/ea-php72 -q /home/userName/public_html/folderName/folderName2/phpFile.php

PHP Code:

print_r($_SERVER['DOCUMENT_ROOT']);

How do we get it to read these global variables?

2

2 Answers

0
votes

For document_root it's normal. You run PHP in command line, so you not used a webserver so you don't have a document_root.

So PHP can't give you this information. Other entries of $_SERVER was not gived when run PHP in command line.

0
votes

There is no server, so $_SERVER is not set.
You are running the script directly as cron cron (as opposed to from a web server accessed by an HTTP request triggered by a cronjob ), then of course it doesn't work.