Auto detect internal/external development environment

后端 未结 5 623
清歌不尽
清歌不尽 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:42

    Of course, if you have use virtual host locally like example.com then the function will be tricked.

    Also if the host is not local but uses a widlcard or default vhost defn and the user adds the IP address to the hosts file locally.

    I would recommend having a directory on the include path which also exists on live but is not replicated there - and simply store:

    function getEnv(){
      return 'Live';
    }
    

    or

    function getEnv(){
      return 'Test';
    }
    

    If both envs are on the same server - you can still do this by setting the include_path in Apache config or .htaccess.

    This also allows you to seperate potentially sensitive env specific data - like database hosts/passwords and encyption keys.

    C.

提交回复
热议问题