skip to Main Content

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

Answers


  1. 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.

    Login or Signup to reply.
  2. 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.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search