php_sapi_name 是用来检测PHP运行环境的函数。
voidphp_sapi_name( void)
该函数返回一个描述PHP与WEB服务器接口的小写字符串。
例如:aolserver, apache,apache2filter, apache2handler, caudium, cgi(until PHP 5.3),cgi-fcgi, cli, continuity, embed, isapi, litespeed, milter, nsapi, phttpd, pi3web, roxen,thttpd, tux, webjames.
<?php
$sapi_type = php_sapi_name();
if (substr($sapi_type, 0, 3) == 'cgi') {
echo "You are using CGI PHP\";
} else {
echo "You are not using CGI PHP\";
}
?>