<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/features.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'zh',
  ),
  'this' => 
  array (
    0 => 'features.commandline.php',
    1 => 'PHP 的命令行模式',
    2 => 'PHP 的命令行模式',
  ),
  'up' => 
  array (
    0 => 'features.php',
    1 => '特点',
  ),
  'prev' => 
  array (
    0 => 'features.persistent-connections.php',
    1 => '持久数据库连接',
  ),
  'next' => 
  array (
    0 => 'features.commandline.differences.php',
    1 => '和其它 SAPI 模块的区别',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'zh',
    'path' => 'features/commandline.xml',
  ),
  'history' => 
  array (
  ),
  'extra_header_links' => 
  array (
    'rel' => 'alternate',
    'href' => '/manual/en/feeds/features.commandline.atom',
    'type' => 'application/atom+xml',
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="features.commandline" class="chapter">
 <h1 class="title">PHP 的命令行模式</h1>
<h2>目录</h2><ul class="chunklist chunklist_chapter"><li><a href="features.commandline.differences.php">和其它 SAPI 模块的区别</a></li><li><a href="features.commandline.options.php">选项</a></li><li><a href="features.commandline.usage.php">用法</a></li><li><a href="features.commandline.io-streams.php">I/O 流</a></li><li><a href="features.commandline.interactive.php">交互式 shell</a></li><li><a href="features.commandline.webserver.php">内置 Web Server</a></li><li><a href="features.commandline.ini.php">INI 配置</a></li></ul>


 
 <div id="features.commandline.introduction" class="section">
  <h2 class="title">简介</h2>
  
  <p class="para">
  <abbr title="Command Line Interpreter/Interface">CLI</abbr> <abbr title="Server Application Programming Interface">SAPI</abbr> 主要是使用 PHP 开发 shell 应用。<abbr title="Command Line Interpreter/Interface">CLI</abbr> <abbr title="Server Application Programming Interface">SAPI</abbr> 与本章中解释的其它 <abbr title="Server Application Programming Interface">SAPI</abbr>
  存在相当多的差异。值得一提的是，尽管 <abbr title="Command Line Interpreter/Interface">CLI</abbr> 和 <code class="literal">CGI</code> 有很多共同的行为，但它们是不同的 <abbr title="Server Application Programming Interface">SAPI</abbr>。
 </p>

 <p class="para">
  <abbr title="Command Line Interpreter/Interface">CLI</abbr> <abbr title="Server Application Programming Interface">SAPI</abbr> 模块会通过默认的 <strong class="option configure">--enable-cli</strong> 参数设置启用，
  也可以在运行 <strong class="command">./configure</strong> 时用参数
  <strong class="option configure">--disable-cli</strong> 来屏蔽。
 </p>

 <p class="para">
  <abbr title="Command Line Interpreter/Interface">CLI</abbr>/<abbr title="Common Gateway Interface">CGI</abbr> 二进制执行文件的文件名、位置和是否存在会根据
  PHP 在系统上的安装而不同。在默认情况下，当运行
  <strong class="command">make</strong> 时，CGI 和 <abbr title="Command Line Interpreter/Interface">CLI</abbr> 都会被编译并且分别放置在
  PHP 源文件目录的 <var class="filename">sapi/cgi/php-cgi</var> 和
  <var class="filename">sapi/cli/php</var> 下。可以注意到两个文件都被命名为了
  php。在 <strong class="command">make install</strong>
  的过程中会发生什么取决于配置行。如果在配置的时候选择了一个
  <abbr title="Server Application Programming Interface">SAPI</abbr>  模块，如 apxs，或者使用了
  <strong class="option configure">--disable-cgi</strong> 参数，则在
  <strong class="command">make install</strong> 的过程中，<abbr title="Command Line Interpreter/Interface">CLI</abbr> 将被拷贝到
  <var class="filename">{PREFIX}/bin/php</var>，除非 <abbr title="Common Gateway Interface">CGI</abbr>
  已经被放置在了那个位置。因此，例如，如果在配置行中有
  <strong class="option configure">--with-apxs</strong>，则在
  <code class="literal">make install</code> 的过程中，<abbr title="Command Line Interpreter/Interface">CLI</abbr> 将被拷贝到
  <code class="literal">{PREFIX}/bin/php</code>。如果希望覆盖 <abbr title="Common Gateway Interface">CGI</abbr>
  执行文件的安装，请在 <strong class="command">make install</strong>
  之后运行 <strong class="command">make install-cli</strong>。或者，也可以在配置行中加上
  <strong class="option configure">--disable-cgi</strong> 参数。
 </p>

 <blockquote class="note"><p><strong class="note">注意</strong>: 
  <p class="para">
   由于 <strong class="option configure">--enable-cli</strong> 和
   <strong class="option configure">--enable-cgi</strong>
   同时默认有效，因此，不必再配置行中加上
   <strong class="option configure">--enable-cli</strong> 来使得 <abbr title="Command Line Interpreter/Interface">CLI</abbr> 在
   <strong class="command">make install</strong> 过程中被拷贝到
   <var class="filename">{PREFIX}/bin/php</var>。
  </p>
 </p></blockquote>

 <p class="para">
  在 Windows 发行包中，<abbr title="Command Line Interpreter/Interface">CLI</abbr> 在主目录中的二进制文件名为
  <var class="filename">php.exe</var>。<abbr title="Common Gateway Interface">CGI</abbr> 版本的文件名为
  <var class="filename">php-cgi.exe</var>。
  如果 PHP 配置使用了
  <strong class="option configure">--enable-cli-win32</strong>，还会有一个额外的 <var class="filename">
  php-win.exe</var> 随包发布。
  它相当于 <abbr title="Command Line Interpreter/Interface">CLI</abbr> 版本，但是 php-win
  不输出任何内容，便不提供控制台（不会弹出“DOS 窗口”）。
 </p>

 <blockquote class="note"><p><strong class="note">注意</strong>: 
  <strong>如何得知自己使用的是哪个 SAPI？</strong><br />
  <p class="para">
   在命令行下，运行 <strong class="command">php -v</strong> 便能得知该
   <var class="filename">php</var> 是 <abbr title="Common Gateway Interface">CGI</abbr> 还是 <abbr title="Command Line Interpreter/Interface">CLI</abbr>。请参考函数
   <span class="function"><a href="function.php-sapi-name.php" class="function">php_sapi_name()</a></span> 以及常量 <strong><code><a href="reserved.constants.php#constant.php-sapi">PHP_SAPI</a></code></strong>。
  </p>
 </p></blockquote>

 <blockquote class="note"><p><strong class="note">注意</strong>: 
  <p class="para">
   在命令行中键入
   <strong class="command">man php</strong> 可以查看 Unix <code class="literal">man</code> 手册页面。
  </p>
 </p></blockquote>
</div>
 

 

 

 
 
 

 
 
 


 
 
 

 
 
 

 
 
 

  

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