Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Sep 2004
    Posts
    60
    Thanks
    1
    Thanked 0 Times in 0 Posts

    environment var in apache not showing up when cron runs

    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:

    Code:
    Array
    (
        [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:

    Code:
    Array
    (
        [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
        [DOCUMENT_ROOT] => 
        [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?

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    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.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • #3
    New Coder
    Join Date
    Sep 2004
    Posts
    60
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Thanks.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •