识别PHP中的开发服务器与生产服务器 [英] Identify development vs. production server in PHP
问题描述
我每天使用两台应用程序服务器:一次开发,一次生产.这些工具箱上有来自不同开发人员的各种应用程序,以及一些通过cron运行的脚本.目前,我正在对-D
标志可以用代码识别我的生产服务器,即isset($_SERVER['DEV'])
.不幸的是,这不适用于从命令行运行的脚本,因为它们不在Apache的保护下.
I work with two application servers on a daily basis: one development, one production. A variety of apps from different developers live on these boxes, as well as some scripts that run via cron. Currently, I am using the -D
flag to httpd so that I can identify my production server in code, ie. isset($_SERVER['DEV'])
. Unfortunately, this does not work for scripts run from the command line since they're not under the Apache umbrella.
本质上,我想要一种清晰,简单的方法来识别每一行代码都可以使用的开发与生产.
Essentially, I would like a clean, simple way to identify development vs. production that is available to every line of code.
我排除的内容:
-
auto_prepend_file
-我们已经在某些应用程序中使用了此伪指令,并且您不能使用多个自动前缀.
auto_prepend_file
-- we are already using this directive in some applications, and you can't have more than one autoprepend.
我目前正在探索的东西:
What I am currently exploring:
- 自定义扩展-我敢肯定,创建一个仅定义新常量(可能受ini设置影响)的新扩展并不是世界上最困难的事情,但是我在这方面没有任何经验. /li>
- Custom extension -- I'm sure creating a new extension that only defines a new constant (possibly influenced by an ini setting) would not be the hardest thing in the world, but I have no prior experience in this area.
那么,有什么技巧可以识别不涉及将代码注入每个脚本或应用程序中的dev/prod?
So, got any tricks for identifying dev/prod that doesn't involve injecting code into every script or application?
推荐答案
使用环境变量
只需设置一个环境变量.它可以在Windows和Linux上运行,现在它们甚至被称为同一个东西.然后只需检查$_ENV["DEVVSPROD"]
这篇关于识别PHP中的开发服务器与生产服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!