Separation of Dev and Production Environments

As a rule developers. programmers and admins tend to be lazy, this is why we have concepts such as shell scripts, crontabs and of course write once, run anywhere. In this case I want to write once but not run anywhere. The condition for not runnning is a determination as to whether or not we want to reach our dev or our production environment. Typically, when I run a dev environment I set up a vhost file that will add an loc prefix to the the domain name for the site I am working on. I will then set my hosts file to direct that vhost's domain name back to an IP on my local machine. For example, when working on my dev version of that domain name would be with a hosts entry pointing to In this exmple I do not want Google Analytics to fire off in a dev environment. By checking the string position of 127 (this should always be the opening segment a local IP address) against, I can quickly determine if I am running in dev or a production environment.

In PHP the logic for checking the host name is as a follows.

strpos(gethostbyname(''), '127')

To avoid running Google Analytics on dev, my code might look like the following.