<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/ref.info.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'zh',
  ),
  'this' => 
  array (
    0 => 'function.php-sapi-name.php',
    1 => 'php_sapi_name',
    2 => '返回 web 服务器和 PHP 之间的接口类型',
  ),
  'up' => 
  array (
    0 => 'ref.info.php',
    1 => 'PHP 选项/信息 函数',
  ),
  'prev' => 
  array (
    0 => 'function.php-ini-scanned-files.php',
    1 => 'php_ini_scanned_files',
  ),
  'next' => 
  array (
    0 => 'function.php-uname.php',
    1 => 'php_uname',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'zh',
    'path' => 'reference/info/functions/php-sapi-name.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="function.php-sapi-name" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">php_sapi_name</h1>
  <p class="verinfo">(PHP 4 &gt;= 4.0.1, PHP 5, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">php_sapi_name</span> &mdash; <span class="dc-title">返回 web 服务器和 PHP 之间的接口类型</span></p>

 </div>
 
 <div class="refsect1 description" id="refsect1-function.php-sapi-name-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>php_sapi_name</strong></span>(): <span class="type"><span class="type"><a href="language.types.string.php" class="type string">string</a></span>|<span class="type"><a href="language.types.singleton.php" class="type false">false</a></span></span></div>

  <p class="simpara">
   返回描述 PHP 所使用的接口类型（the Server API, SAPI）的小写字符串。
   例如，CLI 的 PHP 下这个字符串会是 &quot;cli&quot;，Apache 下可能会有几个不同的值，取决于具体使用的 SAPI。
   以下列出了可能的值。
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.php-sapi-name-parameters">
  <h3 class="title">参数</h3>
  <p class="para">此函数没有参数。</p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.php-sapi-name-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   返回接口类型的小写字符串， 或者在失败时返回 <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong>。
  </p>
  <p class="para">
   尽管不够全面，可能返回的值包括了
   <code class="literal">apache</code>、<code class="literal">apache2handler</code>、<code class="literal">cgi</code>（直到
   PHP 5.3）、<code class="literal">cgi-fcgi</code>、<code class="literal">cli</code>、<code class="literal">cli-server</code>、<code class="literal">embed</code>、<code class="literal">fpm-fcgi</code>、<code class="literal">litespeed</code>、<code class="literal">phpdbg</code>。
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.php-sapi-name-examples">
  <h3 class="title">示例</h3>
  <p class="para">
   <div class="example" id="example-1">
    <p><strong>示例 #1 <span class="function"><strong>php_sapi_name()</strong></span> 示例</strong></p>
    <div class="example-contents"><p>
     以下示例检测了子字符串 <code class="literal">cgi</code>，因为它也有可能会是 <code class="literal">cgi-fcgi</code>。
    </p></div>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br />$sapi_type </span><span style="color: #007700">= </span><span style="color: #0000BB">php_sapi_name</span><span style="color: #007700">();<br />if (</span><span style="color: #0000BB">substr</span><span style="color: #007700">(</span><span style="color: #0000BB">$sapi_type</span><span style="color: #007700">, </span><span style="color: #0000BB">0</span><span style="color: #007700">, </span><span style="color: #0000BB">3</span><span style="color: #007700">) == </span><span style="color: #DD0000">'cgi'</span><span style="color: #007700">) {<br />    echo </span><span style="color: #DD0000">"You are using CGI PHP\n"</span><span style="color: #007700">;<br />} else {<br />    echo </span><span style="color: #DD0000">"You are not using CGI PHP\n"</span><span style="color: #007700">;<br />}<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

   </div>
  </p>
 </div>


 <div class="refsect1 notes" id="refsect1-function.php-sapi-name-notes">
  <h3 class="title">注释</h3>
  <blockquote class="note"><p><strong class="note">注意</strong>: 
   <strong>另一种方法</strong><br />
   <p class="para">
    PHP 常量 <strong><code><a href="reserved.constants.php#constant.php-sapi">PHP_SAPI</a></code></strong> 具有和 <span class="function"><strong>php_sapi_name()</strong></span> 相同的值。
   </p>
  </p></blockquote>
  <div class="tip"><strong class="tip">小技巧</strong>
   <h1 class="title">一个潜在的疑难问题</h1>
   <p class="para">
    定义的 <abbr title="Server Application Programming Interface">SAPI</abbr> 可能不够明显，比如它可能定义为 <code class="literal">apache2handler</code>，而不是 <code class="literal">apache</code>。
   </p>
  </div>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.php-sapi-name-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li><a href="reserved.constants.php#reserved.constants.core" class="link">PHP_SAPI</a></li>
   </ul>
  </p>
 </div>


</div><?php manual_footer($setup); ?>