<?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 => 'en',
  ),
  'this' => 
  array (
    0 => 'features.commandline.php',
    1 => 'Command line usage',
    2 => 'Using PHP from the command line',
  ),
  'up' => 
  array (
    0 => 'features.php',
    1 => 'Features',
  ),
  'prev' => 
  array (
    0 => 'features.persistent-connections.php',
    1 => 'Persistent Database Connections',
  ),
  'next' => 
  array (
    0 => 'features.commandline.differences.php',
    1 => 'Differences to other SAPIs',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'en',
    '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">Using PHP from the command line</h1>
<h2>Table of Contents</h2><ul class="chunklist chunklist_chapter"><li><a href="features.commandline.differences.php">Differences to other SAPIs</a></li><li><a href="features.commandline.options.php">Options</a></li><li><a href="features.commandline.usage.php">Usage</a></li><li><a href="features.commandline.io-streams.php">I/O streams</a></li><li><a href="features.commandline.interactive.php">Interactive shell</a></li><li><a href="features.commandline.webserver.php">Built-in web server</a></li><li><a href="features.commandline.ini.php">INI settings</a></li></ul>

 
 
 
 <div id="features.commandline.introduction" class="section">
  <h2 class="title">Introduction</h2>
  
  <p class="para">
   The main focus of <abbr title="Command Line Interpreter/Interface">CLI</abbr> <abbr title="Server Application Programming Interface">SAPI</abbr>
   is for developing shell applications with PHP. There
   are quite a few differences between the <abbr title="Command Line Interpreter/Interface">CLI</abbr> <abbr title="Server Application Programming Interface">SAPI</abbr> and other
   <abbr title="Server Application Programming Interface">SAPI</abbr>s which are explained in this chapter. It is worth
   mentioning that <abbr title="Command Line Interpreter/Interface">CLI</abbr> and <abbr title="Common Gateway Interface">CGI</abbr> are different
   <abbr title="Server Application Programming Interface">SAPI</abbr>s although they do share many of the same behaviors.
  </p>

  <p class="para">
   The <abbr title="Command Line Interpreter/Interface">CLI</abbr> <abbr title="Server Application Programming Interface">SAPI</abbr> is enabled by default using
   <strong class="option configure">--enable-cli</strong>, but may be disabled using
   the <strong class="option configure">--disable-cli</strong> option when running
   <strong class="command">./configure</strong>.
  </p>
  
  <p class="para">
   The name, location and existence of the <abbr title="Command Line Interpreter/Interface">CLI</abbr>/<abbr title="Common Gateway Interface">CGI</abbr>
   binaries will differ depending on how PHP is installed on your system. By
   default when executing <strong class="command">make</strong>, both the <abbr title="Common Gateway Interface">CGI</abbr>
   and <abbr title="Command Line Interpreter/Interface">CLI</abbr> are built and placed as <var class="filename">sapi/cgi/php-cgi</var> and
   <var class="filename">sapi/cli/php</var> respectively, in your PHP source directory.
   You will note that both are named <var class="filename">php</var>. What happens during
   <strong class="command">make install</strong> depends on your configure line. If a module
   <abbr title="Server Application Programming Interface">SAPI</abbr> is chosen during configure, such as apxs, or the
   <strong class="option configure">--disable-cgi</strong> option is used, the <abbr title="Command Line Interpreter/Interface">CLI</abbr> is
   copied to <var class="filename">{PREFIX}/bin/php</var> during
   <strong class="command">make install</strong> otherwise the <abbr title="Common Gateway Interface">CGI</abbr> is placed
   there. So, for example, if <strong class="option configure">--with-apxs</strong> is
   in your configure line then the <abbr title="Command Line Interpreter/Interface">CLI</abbr> is copied to <var class="filename">{PREFIX}/bin/php
   </var> during <strong class="command">make install</strong>. If you want to override
   the installation of the <abbr title="Common Gateway Interface">CGI</abbr> binary, use <strong class="command">make
   install-cli</strong> after <strong class="command">make install</strong>. Alternatively you
   can specify <strong class="option configure">--disable-cgi</strong> in your configure
   line.
  </p>
  
  <blockquote class="note"><p><strong class="note">Note</strong>: 
   <p class="para">
    Because both <strong class="option configure">--enable-cli</strong> and
    <strong class="option configure">--enable-cgi</strong> are enabled by default,
    simply having <strong class="option configure">--enable-cli</strong> in your
    configure line does not necessarily mean the <abbr title="Command Line Interpreter/Interface">CLI</abbr> will be copied as
    <var class="filename">{PREFIX}/bin/php</var> during <strong class="command">make install</strong>.
   </p>
  </p></blockquote>
  
  <p class="para">
   The <abbr title="Command Line Interpreter/Interface">CLI</abbr> binary is distributed in the main folder as <var class="filename">
   php.exe</var> on Windows. The <abbr title="Common Gateway Interface">CGI</abbr> version is
   distributed as <var class="filename">php-cgi.exe</var>. Additionally, a <var class="filename">
   php-win.exe</var> is distributed if PHP is configured using
   <strong class="option configure">--enable-cli-win32</strong>. This does the same as
   the <abbr title="Command Line Interpreter/Interface">CLI</abbr> version, except that it doesn&#039;t output anything and thus provides
   no console.
  </p>
  
  <blockquote class="note"><p><strong class="note">Note</strong>: 
   <strong>What SAPI do I have?</strong><br />
   <p class="para">
    From a shell, typing <strong class="command">php -v</strong> will tell you
    whether <var class="filename">php</var> is <abbr title="Common Gateway Interface">CGI</abbr> or <abbr title="Command Line Interpreter/Interface">CLI</abbr>. See
    also the function <span class="function"><a href="function.php-sapi-name.php" class="function">php_sapi_name()</a></span> and the constant
    <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">Note</strong>: 
   <p class="para">
    A Unix <code class="literal">man</code>ual page is available by typing <strong class="command">man
    php</strong> in the shell environment.
   </p>
  </p></blockquote>
 </div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

 
 
 

 
 
 

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