View Full Version : environment var in apache not showing up when cron runs

01-05-2011, 07:45 PM
In /etc/httpd/conf/httpd.conf there is:

SetEnv ENV development

When calling a page in a browser and displaying the values in the php $_SERVER variable, the 'ENV' value shows up appropriately:

[ENV] => development

However, when running a cron job, 'ENV' does not show up.

For reference, here are values found in the $_SERVER variable when running as a cron:

[SHELL] => /bin/sh
[USER] => root
[PATH] => /usr/bin:/bin
[PWD] => /var/www/luxurylink/php/shell
[SHLVL] => 1
[HOME] => /root
[LOGNAME] => root
[OLDPWD] => /root
[_] => /usr/bin/php
[PHP_SELF] => server_vars.php
[SCRIPT_NAME] => server_vars.php
[SCRIPT_FILENAME] => server_vars.php
[PATH_TRANSLATED] => server_vars.php
[REQUEST_TIME] => 1294252561
[argv] => Array
[0] => server_vars.php

[argc] => 1

How do you get the 'ENV' value to show up when running a cron job?

01-05-2011, 08:53 PM
PHP has no direct relationship to apache. You are executing CLI PHP and it will not be affected by environmental variables stated by the httpd.conf. I'm not a cron wizard by any far stretch of the imagination, but I'll try to help here too.

You should be able to add more environmental variables to the cron file, but I don't believe there is a way to make it call specific aside from passing in a querystring; however, I believe the 'SHELL' or 'SHLVL' environmental variable only shows up when invoked from cron, or at least that SHLVL I'm thinking will be able to indicate how its called. It really is hard to say on that one though.
Play around with the SHELL and SHLVL in your PHP script with CRON and non-CRON CLI calls and see if they change at all. I wouldn't go by passing a querystring if you can avoid it.

01-06-2011, 08:28 PM