<?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 => 'ja',
  ),
  'this' => 
  array (
    0 => 'features.commandline.php',
    1 => 'コマンドラインの使用法',
    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' => 'ja',
    '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">PHP ファイルの実行</a></li><li><a href="features.commandline.io-streams.php">I/O ストリーム</a></li><li><a href="features.commandline.interactive.php">対話シェル</a></li><li><a href="features.commandline.webserver.php">ビルトインウェブサーバー</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
   で開発することです。<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> と <abbr title="Common Gateway Interface">CGI</abbr>
   は多くの共通点がありますが、別の <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> を実行したときには、<abbr title="Common Gateway Interface">CGI</abbr> と
   <abbr title="Command Line Interpreter/Interface">CLI</abbr> が両方ビルドされて、それぞれ PHP ソースディレクトリの <var class="filename">sapi/cgi/php-cgi</var> と
   <var class="filename">sapi/cli/php</var> にできあがります。
   両方とも <var class="filename">php</var> という名前であることに注意しましょう。
   <strong class="command">make install</strong> のときにどうなるかは、configure
   行に依存します。
   configure で例えば apxs のような <abbr title="Server Application Programming Interface">SAPI</abbr> モジュールが選択された場合、または
   <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> がそこにコピーされます。
   つまり、たとえば configure で <strong class="option configure">--with-apxs </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="command">make install</strong> の後に <strong class="command">make install-cli</strong>
   を実行してください。あるいは configure で
   <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>
    の両方がデフォルトで有効になっています。そのため、configure で
    <strong class="option configure">--enable-cli</strong>
    を指定したからといって、<strong class="command">make install</strong> で
    <var class="filename">{PREFIX}/bin/php</var> 
    にコピーされるのが必ずしも <abbr title="Command Line Interpreter/Interface">CLI</abbr> になるとは限りません。
   </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>
   として配布されます。さらに
   configure で <strong class="option configure">--enable-cli-win32</strong>
   を指定すると、新しく <var class="filename">php-win.exe</var> というファイルが配布されます。
   これは <abbr title="Command Line Interpreter/Interface">CLI</abbr> バージョンとほぼ同じですが、何も出力しないため、コンソールは必要ありません。
  </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">
    Unix の <code class="literal">man</code> ページは、
    シェル環境から <strong class="command">man php</strong> とすれば見ることができます。
   </p>
  </p></blockquote>
 </div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

 
 
 

 
 
 

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