I love the salt water evaporates in Zend Framework. I'm able to know which atmosphere I am presently using by checking APPLICATION_ENV constant during my controller.

<VirtualHost *:80>
    #ServerName 
    #DocumentRoot

        SetEnv APPLICATION_ENV "development"

    # Directory
</VirtualHost>

But regrettably I can not use ZF during my current project. How do i take a look atmosphere variable during my PHP code?

Since SetEnv set's the worthiness to Apache's atmosphere, you will get it with

  • [cde] — Have an Apache subprocess_env variable

or simply

  • [cde] — Will get the need for an atmosphere variable

Should you take a look at apache_getenv inside a ZF project, you will notice ZF uses getenv:

public/index.php

An frequently use alternative is always to browse the Hostname from PHP and define the continual accordingly:

getenv

By doing this, it's not necessary to depend around the atmosphere setting whatsoever.

[cde] defines an atmosphere variable.

Once it has been set (in both your Apache's configuration, or in the system level), read its value while using [cde] function :

// Define application environment
defined('APPLICATION_ENV')
    || define('APPLICATION_ENV', (getenv('APPLICATION_ENV') ? 
                                  getenv('APPLICATION_ENV') : 
                                  'production'));


For example, if you are using this inside your if(!defined('APPLICATION_ENV')) { if(FALSE === stripos($_SERVER['SERVER_NAME']), 'www.example.com') { define(APPLICATION_ENV, 'development'); } else { define(APPLICATION_ENV, 'production'); } } file :

SetEnv

This can be used part of PHP code :

getenv

And you will get :

echo getenv('APPLICATION_ENV');