(PHP 4 >= 4.0.1, PHP 5)
php_sapi_name — 返回 web 服務(wù)器和 PHP 之間的接口類型
說明
string php_sapi_name ( void )返回描述 PHP 所使用的接口類型(the Server API, SAPI)的小寫字符串。 例如,CLI 的 PHP 下這個字符串會是 "cli",Apache 下可能會有幾個不同的值,取決于具體使用的 SAPI。 以下列出了可能的值。
返回值
返回接口類型的小寫字符串。
盡管不夠全面,可能返回的值包括了 aolserver、apache、 apache2filter、apache2handler、 caudium、cgi (直到 PHP 5.3), cgi-fcgi、cli、 continuity、embed、 isapi、litespeed、 milter、nsapi、 phttpd、pi3web、roxen、 thttpd、tux 和 webjames。
范例
Example #1 php_sapi_name() 例子
以下例子檢測了子字符串 cgi,因為它也有可能會是 cgi-fcgi。
<?php
$sapi_type = php_sapi_name();
if (substr($sapi_type, 0, 3) == 'cgi') {
echo "You are using CGI PHPn";
} else {
echo "You are not using CGI PHPn";
}
?>
注釋
Note:
另一種方法
PHP 常量 PHP_SAPI
具有和 php_sapi_name() 相同的值。
定義的 SAPI 可能不夠明顯,比如它可能定義為 apache2handler 或 apache2filter,而不是 apache
參見
PHP_SAPI