Lloyd Banks Lloyd Banks - 4 months ago 53
PHP Question

PHP - Environment Variables Not Available When Script Called From Cron Job / Command Line


file looks like:


echo $_SERVER["myEnvVariable"];
echo getenv("myEnvVariable");

The above will return my set environment variable twice. It works when the script is called from outside the server.

If I call the same script on the server using the command line command:

php test.php

or using a cronjob

****** curl http://localhost/test.php

nothing is returned.

How do I make available my environment variables within the server itself? I am setting my environment variables within the Apache


Execute the cron job this way:

myEnvVariable=value php test.php

Variable will be available from getenv("myEnvVariable"), not in $_SERVER.