Home  >  Article  >  Backend Development  >  解析如何通过PHP函数获取当前运行的环境 来进行判断执行逻辑(小技巧)_php技巧

解析如何通过PHP函数获取当前运行的环境 来进行判断执行逻辑(小技巧)_php技巧

PHP中文网
PHP中文网Original
2018-05-14 09:39:202902browse

一般情况下,我们的运行环境是 apache,当然也有些人是用IIS环境的
我们要是想知道我们目前运行的环境是什么的话,那我们只需要用函数php_sapi_name()来测试
进行比较判断处理
函数:php_sapi_name();
在apache环境下面输出的结果是“apache2handler”;
在cgi模式下输出的结果是“cgi-fcgi”
要是在命令行模式下面运行的话,那么输出的结果是:”cli”

以上就是解析如何通过PHP函数获取当前运行的环境 来进行判断执行逻辑(小技巧)_php技巧的内容,更多相关内容请关注PHP中文网(www.php.cn)!


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn