Auto detect internal/external development environment

后端 未结 5 633
清歌不尽
清歌不尽 2021-02-04 14:04

We use the following function to auto detect if we are on a machine internally or on a live server and then choose the appropriate configs for various components:



        
5条回答
  •  心在旅途
    2021-02-04 14:33

    Set an environment variable in your Apache virtual host configuration. This is the way the Zend Framework does it.

    See the ZF quick start guide for an example (the "Create a Virtual Host" section.)

    In your httpd.conf or a .htaccess file, put:

    SetEnv APPLICATION_ENV "development"
    

    Then in your application, use the getenv function to get the value:

    $environment = getenv("APPLICATION_ENV");
    if ($environment == "development")
    {
        // do development stuff
    }
    else if ($environment == "live")
    {
        // do live stuff
    }
    

提交回复
热议问题