Cpanel Cron Job Php Global Variable

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?

Upvotes: 0

Views: 303

Answers (2)

Hammad Ahmed khan
Hammad Ahmed khan

Reputation: 1671

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.

Upvotes: 0

Inazo
Inazo

Reputation: 498

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.

Upvotes: 0

Related Questions