<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/features.commandline.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'fr',
  ),
  'this' => 
  array (
    0 => 'features.commandline.differences.php',
    1 => 'Diff&eacute;rences avec les autres SAPIs',
    2 => 'Diff&eacute;rences avec les autres SAPIs',
  ),
  'up' => 
  array (
    0 => 'features.commandline.php',
    1 => 'Utilisation des lignes de commande',
  ),
  'prev' => 
  array (
    0 => 'features.commandline.php',
    1 => 'Utilisation des lignes de commande',
  ),
  'next' => 
  array (
    0 => 'features.commandline.options.php',
    1 => 'Options',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'fr',
    'path' => 'features/commandline.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="features.commandline.differences" class="section">
  <h2 class="title">Différences avec les autres <abbr title="Server Application Programming Interface">SAPI</abbr>s</h2>
  
  <p class="para">
   Les différences les plus notables entre le <abbr title="Command Line Interpreter/Interface">CLI</abbr> <abbr title="Server Application Programming Interface">SAPI</abbr> et les
   <abbr title="Server Application Programming Interface">SAPI</abbr> sont :
   <ul class="itemizedlist">
    <li class="listitem">
     <p class="para">
      Contrairement au <abbr title="Common Gateway Interface">CGI</abbr> <abbr title="Server Application Programming Interface">SAPI</abbr>, aucun
      en-tête HTTP n&#039;est écrit dans le résultat.
     </p>
     <p class="para">
      Bien que le <abbr title="Common Gateway Interface">CGI</abbr> <abbr title="Server Application Programming Interface">SAPI</abbr> fournisse un
      moyen de supprimer les en-têtes HTTP, il n&#039;est pas possible d&#039;activer les
      en-têtes HTTP dans le <abbr title="Command Line Interpreter/Interface">CLI</abbr> <abbr title="Server Application Programming Interface">SAPI</abbr>.
     </p>
     <p class="para">
      <abbr title="Command Line Interpreter/Interface">CLI</abbr> est lancé en mode silencieux par défaut, bien que les options
      <strong class="option unknown">-q</strong> et <strong class="option unknown">--no-header</strong> soient gardées
      pour rester compatible avec les anciennes versions <abbr title="Common Gateway Interface">CGI</abbr>.
     </p>
     <p class="para">
      Il ne change pas le répertoire courant en celui du script.
      (les options <strong class="option unknown">-C</strong> et <strong class="option unknown">--no-chdir</strong> sont
      gardées par souci de compatibilité)
     </p>
     <p class="para">
      Messages d&#039;erreurs en texte brut (pas de formatage <abbr title="Hyper Text Markup Language">HTML</abbr>).
     </p>
    </li>
    <li class="listitem">
     <p class="para">
      Il y a plusieurs directives du <var class="filename">php.ini</var> qui sont redéfinies par le
      <abbr title="Command Line Interpreter/Interface">CLI</abbr> <abbr title="Server Application Programming Interface">SAPI</abbr>, car elles n&#039;ont pas de sens en environnement shell :
     </p>
     <p class="para">
      <table class="doctable table">
       <caption><strong>Directives <var class="filename">php.ini</var> redéfinies</strong></caption>
       
        <thead>
         <tr>
          <th>Directive</th>
          <th>Valeur par défaut pour <abbr title="Command Line Interpreter/Interface">CLI</abbr> <abbr title="Server Application Programming Interface">SAPI</abbr></th>
          <th>Commentaire</th>
         </tr>

        </thead>

        <tbody class="tbody">
         <tr>
          <td><a href="errorfunc.configuration.php#ini.html-errors" class="link">html_errors</a></td>
          <td><strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong></td>
          <td>
           Par défaut à <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong>, vu qu&#039;il peut être bien difficile de lire des messages
           d&#039;erreur sur un terminal lorsqu&#039;ils sont noyés dans des balises <abbr title="Hyper Text Markup Language">HTML</abbr>
           non-interprétées.
          </td>
         </tr>

         <tr>
          <td><a href="outcontrol.configuration.php#ini.implicit-flush" class="link">implicit_flush</a></td>
          <td><strong><code><a href="reserved.constants.php#constant.true">true</a></code></strong></td>
          <td>
           Dans un terminal, il est généralement souhaitable que tout affichage en provenance de
           <span class="function"><a href="function.print.php" class="function">print</a></span>,
           <span class="function"><a href="function.echo.php" class="function">echo</a></span>
           et autres, soit immédiatement affiché, et non pas placé dans un
           buffer quelconque. Néanmoins, il est toujours possible d&#039;utiliser
           <a href="ref.outcontrol.php" class="link">la bufferisation de sortie</a>
           pour retarder un affichage, ou bien en manipuler le contenu
           une dernière fois.
          </td>
         </tr>

         <tr>
          <td><a href="info.configuration.php#ini.max-execution-time" class="link">max_execution_time</a></td>
          <td>0 (sans limite)</td>
          <td>
           PHP dans un terminal est susceptible d&#039;être utilisé pour des tâches
           bien plus diverses que dans des scripts web, et vu que cela
           prend généralement beaucoup de temps, ce paramètre sera défini par défaut
           à 0 permettant ainsi d&#039;être illimité.
          </td>
         </tr>

         <tr>
          <td><a href="ini.core.php#ini.register-argc-argv" class="link">register_argc_argv</a></td>
          <td><strong><code><a href="reserved.constants.php#constant.true">true</a></code></strong></td>
          <td>
           <p class="para">
            La définition à <strong><code><a href="reserved.constants.php#constant.true">true</a></code></strong> de cette directive signifie que les scripts
            exécutés via le <abbr title="Server Application Programming Interface">SAPI</abbr> <abbr title="Command Line Interpreter/Interface">CLI</abbr> auront toujours
            accès à <em>argc</em> (représentant le nombre
            d&#039;arguments passés à l&#039;application) et
            <em>argv</em> (le tableau contenant les arguments passés).
           </p>
           <p class="para">
            Les variables PHP <var class="varname"><a href="reserved.variables.argc.php" class="classname">$argc</a></var>
            et <var class="varname"><a href="reserved.variables.argv.php" class="classname">$argv</a></var> sont automatiquement définies et remplies
            avec les valeurs appropriées, lors de l&#039;utilisation du 
            <abbr title="Server Application Programming Interface">SAPI</abbr> <abbr title="Command Line Interpreter/Interface">CLI</abbr>. Ces valeurs peuvent également
            être trouvées dans la variable <var class="varname"><a href="reserved.variables.server.php" class="classname">$_SERVER</a></var>, par exemple :
            <var class="varname"><a href="reserved.variables.server.php" class="classname">$_SERVER['argv']</a></var>.
           </p>
           <div class="warning"><strong class="warning">Avertissement</strong>
           <p class="para">
            La présence de <var class="varname"><a href="reserved.variables.argv.php" class="classname">$argv</a></var> ou <var class="varname"><a href="reserved.variables.server.php" class="classname">$_SERVER['argv']</a></var>
            n&#039;est pas une indication fiable qu&#039;un script est exécuté depuis la
            ligne de commande, car ces variables peuvent être définies dans d&#039;autres contextes
            lorsque <a href="ini.core.php#ini.register-argc-argv" class="link">register_argc_argv</a> est activé.
            La valeur retournée par <span class="function"><a href="function.php-sapi-name.php" class="function">php_sapi_name()</a></span> devrait être vérifiée
            à la place.
            <div class="informalexample">
             <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br /><br /></span><span style="color: #007700">if (</span><span style="color: #0000BB">php_sapi_name</span><span style="color: #007700">() === </span><span style="color: #DD0000">'cli'</span><span style="color: #007700">) {<br />    echo </span><span style="color: #DD0000">"Ce script est exécuté depuis la ligne de commande !\n"</span><span style="color: #007700">;<br />}</span></span></code></div>
             </div>

            </div>
           </p>
          </div>
          </td>
         </tr>

         <tr>
          <td><a href="outcontrol.configuration.php#ini.output-buffering" class="link">output_buffering</a></td>
          <td><strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong></td>
          <td>
           <p class="para">
            Même si cette configuration INI est codée en dur à <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong>,
            les fonctions relatives à
            <a href="book.outcontrol.php" class="link">l&#039;affichage du buffer</a>
            sont disponibles.
           </p>
          </td>
         </tr>

         <tr>
          <td><a href="info.configuration.php#ini.max-input-time" class="link">max_input_time</a></td>
          <td><strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong></td>
          <td>
           <p class="para">
            Le PHP <abbr title="Command Line Interpreter/Interface">CLI</abbr> ne supporte pas GET, POST et le téléchargement de fichiers.
           </p>
          </td>
         </tr>

        </tbody>
       
      </table>

     </p>
     <blockquote class="note"><p><strong class="note">Note</strong>: 
      <p class="para">
       Ces directives ne peuvent pas être initialisées avec d&#039;autres valeurs
       dans le fichier <var class="filename">php.ini</var> ou par une autre méthode. C&#039;est une limitation,
       car ces valeurs par défaut s&#039;appliquent une fois que tous les autres
       fichiers de configuration ont été analysés. Cependant, ces
       valeurs peuvent être modifiées durant l&#039;exécution (ce qui n&#039;est pas
       logique pour certaines directives, comme
       <a href="ini.core.php#ini.register-argc-argv" class="link">register_argc_argv</a>).
      </p>
     </p></blockquote>
     <blockquote class="note"><p><strong class="note">Note</strong>: 
      <p class="para">
       Il est recommandé de définir
       <a href="misc.configuration.php#ini.ignore-user-abort" class="link">ignore_user_abort</a> pour
       les scripts en ligne de commande. Voir la fonction
       <span class="function"><a href="function.ignore-user-abort.php" class="function">ignore_user_abort()</a></span> pour plus d&#039;informations.
      </p>
     </p></blockquote>
    </li>
    
    <li class="listitem">
     <p class="para">
      Pour faciliter le travail en environnement shell, plusieurs constantes
      sont définies pour les <a href="features.commandline.io-streams.php" class="link">flux
      I/O</a>.
     </p>
    </li>
    
    <li class="listitem">
     <p class="para">
      Le <abbr title="Command Line Interpreter/Interface">CLI</abbr> <abbr title="Server Application Programming Interface">SAPI</abbr> <strong>ne transforme pas</strong>
      le dossier courant en dossier d&#039;exécution du script.
     </p>
     <div class="example" id="example-1">
      <p><strong>Exemple #1 
       Exemple montrant la différence avec le <abbr title="Server Application Programming Interface">SAPI</abbr>
       <abbr title="Common Gateway Interface">CGI</abbr> :
      </strong></p>
      <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br /></span><span style="color: #FF8000">// Un test simple : affiche le dossier d'exécution<br /></span><span style="color: #007700">echo </span><span style="color: #0000BB">getcwd</span><span style="color: #007700">(), </span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
      </div>

      <div class="example-contents"><p>
       Lors de l&#039;utilisation de la version <abbr title="Common Gateway Interface">CGI</abbr>, l&#039;affichage sera :
      </p></div>
      <div class="example-contents screen">
<div class="cdata"><pre>
$ pwd
/tmp

$ php -q autre_dossier/test.php
/tmp/autre_dossier
</pre></div>
      </div>
      <div class="example-contents"><p>
       Cela montre clairement que PHP modifie le dossier
       courant, et utilise le dossier du script exécuté.
      </p></div>
      <div class="example-contents"><p>
       En utilisant le <abbr title="Command Line Interpreter/Interface">CLI</abbr> <abbr title="Server Application Programming Interface">SAPI</abbr>, on obtient :
      </p></div>
      <div class="example-contents screen">
<div class="cdata"><pre>
$ pwd
/tmp

$ php -f autre_dossier/test.php
/tmp
</pre></div>
      </div>
      <div class="example-contents"><p>
       Cela donne beaucoup plus de souplesse lors de la rédaction de
       scripts shell avec PHP.
      </p></div>
     </div>
     <blockquote class="note"><p><strong class="note">Note</strong>: 
      <p class="para">
       Le <abbr title="Common Gateway Interface">CGI</abbr> <abbr title="Server Application Programming Interface">SAPI</abbr> se comporte de la même façon que le
       <abbr title="Command Line Interpreter/Interface">CLI</abbr> <abbr title="Server Application Programming Interface">SAPI</abbr>, en lui passant l&#039;option
       <strong class="option unknown">-C</strong>, lorsqu&#039;il est invoqué en ligne de commande.
      </p>
     </p></blockquote>
    </li>
   </ul>
  </p>
 </div><?php manual_footer($setup); ?>