<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <title>Command line options</title> </head> <body><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="features.commandline.differences.html">Differences to other SAPIs</a></div> <div class="next" style="text-align: right; float: right;"><a href="features.commandline.usage.html">Usage</a></div> <div class="up"><a href="features.commandline.html">Command line usage</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div><hr /><div id="features.commandline.options" class="section"> <h2 class="title">Command line options</h2> <p class="para"> The list of command line options provided by the PHP binary can be queried at any time by running PHP with the <strong class="option unknown">-h</strong> switch: <div class="example-contents screen"> <div class="cdata"><pre> Usage: php [options] [-f] <file> [--] [args...] php [options] -r <code> [--] [args...] php [options] [-B <begin_code>] -R <code> [-E <end_code>] [--] [args...] php [options] [-B <begin_code>] -F <file> [-E <end_code>] [--] [args...] php [options] -- [args...] php [options] -a -a Run interactively -c <path>|<file> Look for php.ini file in this directory -n No php.ini file will be used -d foo[=bar] Define INI entry foo with value 'bar' -e Generate extended information for debugger/profiler -f <file> Parse and execute <file>. -h This help -i PHP information -l Syntax check only (lint) -m Show compiled in modules -r <code> Run PHP <code> without using script tags <?..?> -B <begin_code> Run PHP <begin_code> before processing input lines -R <code> Run PHP <code> for every input line -F <file> Parse and execute <file> for every input line -E <end_code> Run PHP <end_code> after processing all input lines -H Hide any passed arguments from external tools. -S <addr>:<port> Run with built-in web server. -t <docroot> Specify document root <docroot> for built-in web server. -s Output HTML syntax highlighted source. -v Version number -w Output source with stripped comments and whitespace. -z <file> Load Zend extension <file>. args... Arguments passed to script. Use -- args when first argument starts with - or script is read from stdin --ini Show configuration file names --rf <name> Show information about function <name>. --rc <name> Show information about class <name>. --re <name> Show information about extension <name>. --rz <name> Show information about Zend extension <name>. --ri <name> Show configuration for extension <name>. </pre></div> </div> </p> <p class="para"> <table class="doctable table"> <caption><strong>Command line options</strong></caption> <thead> <tr> <th>Option</th> <th>Long Option</th> <th>Description</th> </tr> </thead> <tbody class="tbody"> <tr> <td>-a</td> <td>--interactive</td> <td> <p class="para"> Run PHP interactively. For more information, see the <a href="features.commandline.interactive.html" class="link">Interactive shell</a> section. </p> </td> </tr> <tr> <td>-b</td> <td>--bindpath</td> <td> <p class="para"> Bind Path for external FASTCGI Server mode (<acronym title="Common Gateway Interface">CGI</acronym> only). </p> </td> </tr> <tr> <td>-C</td> <td>--no-chdir</td> <td> <p class="para"> Do not chdir to the script's directory (<acronym title="Common Gateway Interface">CGI</acronym> only). </p> </td> </tr> <tr> <td>-q</td> <td>--no-header</td> <td> <p class="para"> Quiet-mode. Suppress <acronym title="Hypertext Transfer Protocol">HTTP</acronym> header output (<acronym title="Common Gateway Interface">CGI</acronym> only). </p> </td> </tr> <tr> <td>-T</td> <td>--timing</td> <td> <p class="para"> Measure execution time of script repeated <var class="varname"><var class="varname">count</var></var> times (<acronym title="Common Gateway Interface">CGI</acronym> only). </p> </td> </tr> <tr> <td>-c</td> <td>--php-ini</td> <td> <p class="para"> Specifies either a directory in which to look for <var class="filename">php.ini</var>, or a custom <em>INI</em> file (which does not need to be named <var class="filename">php.ini</var>), e.g.: </p> <p class="para"><div class="informalexample"> <div class="example-contents screen"> <div class="cdata"><pre> $ php -c /custom/directory/ my_script.php $ php -c /custom/directory/custom-file.ini my_script.php </pre></div> </div> </div></p> <p class="para"> If this option is not specified, <var class="filename">php.ini</var> is searched for in the <a href="configuration.file.html" class="link">default locations</a>. </p> </td> </tr> <tr> <td>-n</td> <td>--no-php-ini</td> <td> <p class="para"> Ignore <var class="filename">php.ini</var> completely. </p> </td> </tr> <tr> <td>-d</td> <td>--define</td> <td> <p class="para"> Set a custom value for any of the configuration directives allowed in <var class="filename">php.ini</var>. The syntax is: <div class="example-contents screen"> <div class="cdata"><pre> -d configuration_directive[=value] </pre></div> </div> </p> <p class="para"><div class="example" id="example-364"> <div class="example-contents screen"> <div class="cdata"><pre> # Omitting the value part will set the given configuration directive to "1" $ php -d max_execution_time -r '$foo = ini_get("max_execution_time"); var_dump($foo);' string(1) "1" # Passing an empty value part will set the configuration directive to "" php -d max_execution_time= -r '$foo = ini_get("max_execution_time"); var_dump($foo);' string(0) "" # The configuration directive will be set to anything passed after the '=' character $ php -d max_execution_time=20 -r '$foo = ini_get("max_execution_time"); var_dump($foo);' string(2) "20" $ php -d max_execution_time=doesntmakesense -r '$foo = ini_get("max_execution_time"); var_dump($foo);' string(15) "doesntmakesense" </pre></div> </div> </div></p> </td> </tr> <tr> <td>-e</td> <td>--profile-info</td> <td> <p class="para"> Activate the extended information mode, to be used by a debugger/profiler. </p> </td> </tr> <tr> <td>-f</td> <td>--file</td> <td> <p class="para"> Parse and execute the specified file. The <strong class="option unknown">-f</strong> is optional and may be omitted - providing just the filename to execute is sufficient. </p> <blockquote class="note"><p><strong class="note">Note</strong>: <p class="para"> To pass arguments to a script, the first argument must be <em>--</em>, otherwise PHP will interpret them as PHP options. </p> </p></blockquote> </td> </tr> <tr> <td>-h and -?</td> <td>--help and --usage</td> <td> Output a list of command line options with one line descriptions of what they do. </td> </tr> <tr> <td>-i</td> <td>--info</td> <td> Calls <span class="function"><a href="function.phpinfo.html" class="function">phpinfo()</a></span>, and prints out the results. If PHP is not working correctly, it is advisable to use the command <strong class="command">php -i</strong> and see whether any error messages are printed out before or in place of the information tables. Beware that when using the <acronym title="Common Gateway Interface">CGI</acronym> mode the output is in <acronym title="Hyper Text Markup Language">HTML</acronym> and therefore very large. </td> </tr> <tr> <td>-l</td> <td>--syntax-check</td> <td> <p class="para"> Provides a convenient way to perform only a syntax check on the given PHP code. On success, the text <em>No syntax errors detected in <filename></em> is written to standard output and the shell return code is <em>0</em>. On failure, the text <em>Errors parsing <filename></em> in addition to the internal parser error message is written to standard output and the shell return code is set to <em>-1</em>. </p> <p class="para"> This option won't find fatal errors (like undefined functions). Use the <strong class="option unknown">-f</strong> to test for fatal errors too. </p> <blockquote class="note"><p><strong class="note">Note</strong>: <p class="para"> This option does not work together with the <strong class="option unknown">-r</strong> option. </p> </p></blockquote> </td> </tr> <tr> <td>-m</td> <td>--modules</td> <td> <p class="para"><div class="example" id="example-365"> <p><strong>Example #1 Printing built in (and loaded) PHP and Zend modules</strong></p> <div class="example-contents screen"> <div class="cdata"><pre> $ php -m [PHP Modules] xml tokenizer standard session posix pcre overload mysql mbstring ctype [Zend Modules] </pre></div> </div> </div></p> </td> </tr> <tr> <td>-r</td> <td>--run</td> <td> <p class="para"> Allows execution of PHP included directly on the command line. The PHP start and end tags (<em><?php</em> and <em>?></em>) are <em class="emphasis">not needed</em> and will cause a parse error if present. </p> <blockquote class="note"><p><strong class="note">Note</strong>: <p class="para"> Care must be taken when using this form of PHP not to collide with command line variable substitution done by the shell. </p> <div class="example" id="example-366"> <p><strong>Example #2 Getting a syntax error when using double quotes</strong></p> <div class="example-contents screen"> <div class="cdata"><pre> $ php -r "$foo = get_defined_constants();" PHP Parse error: syntax error, unexpected '=' in Command line code on line 1 Parse error: syntax error, unexpected '=' in Command line code on line 1 </pre></div> </div> </div> <p class="para"> The problem here is that sh/bash performs variable substitution even when using double quotes <em>"</em>. Since the variable <var class="varname"><var class="varname">$foo</var></var> is unlikely to be defined, it expands to nothing which results in the code passed to PHP for execution actually reading: </p> <div class="informalexample"> <div class="example-contents screen"> <div class="cdata"><pre> $ php -r " = get_defined_constants();" </pre></div> </div> </div> <p class="para"> The correct way would be to use single quotes <em>'</em>. Variables in single-quoted strings are not expanded by sh/bash. </p> <div class="example" id="example-367"> <p><strong>Example #3 Using single quotes to prevent the shell's variable substitution</strong></p> <div class="example-contents screen"> <div class="cdata"><pre> $ php -r '$foo = get_defined_constants(); var_dump($foo);' array(370) { ["E_ERROR"]=> int(1) ["E_WARNING"]=> int(2) ["E_PARSE"]=> int(4) ["E_NOTICE"]=> int(8) ["E_CORE_ERROR"]=> [...] </pre></div> </div> </div> <p class="para"> If using a shell other than sh/bash, further issues might be experienced - if appropriate, a bug report should be opened at <a href="http://bugs.php.net/" class="link external">» http://bugs.php.net/</a>. It is still easy to run into trouble when trying to use variables (shell or PHP) in commnad-line code, or using backslashes for escaping, so take great care when doing so. You have been warned! </p> </p></blockquote> <blockquote class="note"><p><strong class="note">Note</strong>: <p class="para"> <strong class="option unknown">-r</strong> is available in the <acronym title="Command Line Interpreter/Interface">CLI</acronym> <acronym title="Server Application Programming Interface">SAPI</acronym>, but not in the <em class="emphasis">CGI</em> <acronym title="Server Application Programming Interface">SAPI</acronym>. </p> </p></blockquote> <blockquote class="note"><p><strong class="note">Note</strong>: <p class="para"> This option is only intended for very basic code, so some configuration directives (such as <a href="ini.core.html#ini.auto-prepend-file" class="link">auto_prepend_file</a> and <a href="ini.core.html#ini.auto-append-file" class="link">auto_append_file</a>) are ignored in this mode. </p> </p></blockquote> </td> </tr> <tr> <td>-B</td> <td>--process-begin</td> <td> <p class="para"> PHP code to execute before processing stdin. Added in PHP 5. </p> </td> </tr> <tr> <td>-R</td> <td>--process-code</td> <td> <p class="para"> PHP code to execute for every input line. Added in PHP 5. </p> <p class="para"> There are two special variables available in this mode: <var class="varname"><var class="varname">$argn</var></var> and <var class="varname"><var class="varname">$argi</var></var>. <var class="varname"><var class="varname">$argn</var></var> will contain the line PHP is processing at that moment, while <var class="varname"><var class="varname">$argi</var></var> will contain the line number. </p> </td> </tr> <tr> <td>-F</td> <td>--process-file</td> <td> <p class="para"> PHP file to execute for every input line. Added in PHP 5. </p> </td> </tr> <tr> <td>-E</td> <td>--process-end</td> <td> <p class="para"> PHP code to execute after processing the input. Added in PHP 5. </p> <p class="para"><div class="example" id="example-368"> <p><strong>Example #4 Using the <strong class="option unknown">-B</strong> , <strong class="option unknown">-R</strong> and <strong class="option unknown">-E</strong> options to count the number of lines of a project. </strong></p> <div class="example-contents screen"> <div class="cdata"><pre> $ find my_proj | php -B '$l=0;' -R '$l += count(@file($argn));' -E 'echo "Total Lines: $l\n";' Total Lines: 37328 </pre></div> </div> </div></p> </td> </tr> <tr> <td>-S</td> <td>--server</td> <td> <p class="para"> Starts <a href="features.commandline.webserver.html" class="link">built-in web server</a>. Available as of PHP 5.4.0. </p> </td> </tr> <tr> <td>-t</td> <td>--docroot</td> <td> Specifies document root for <a href="features.commandline.webserver.html" class="link">built-in web server</a>. Available as of PHP 5.4.0. </td> </tr> <tr> <td>-s</td> <td>--syntax-highlight and --syntax-highlighting</td> <td> <p class="para"> Display colour syntax highlighted source. </p> <p class="para"> This option uses the internal mechanism to parse the file and writes an HTML highlighted version of it to standard output. Note that all it does is generate a block of <em><code> [...] </code></em> HTML tags, no HTML headers. </p> <blockquote class="note"><p><strong class="note">Note</strong>: <p class="para"> This option does not work together with the <strong class="option unknown">-r</strong> option. </p> </p></blockquote> </td> </tr> <tr> <td>-v</td> <td>--version</td> <td> <p class="para"><div class="example" id="example-369"> <p><strong>Example #5 Using <strong class="option unknown">-v</strong> to get the <acronym title="Server Application Programming Interface">SAPI</acronym> name and the version of PHP and Zend</strong></p> <div class="example-contents screen"> <div class="cdata"><pre> $ php -v PHP 5.3.1 (cli) (built: Dec 11 2009 19:55:07) Copyright (c) 1997-2009 The PHP Group Zend Engine v2.3.0, Copyright (c) 1998-2009 Zend Technologies </pre></div> </div> </div></p> </td> </tr> <tr> <td>-w</td> <td>--strip</td> <td> <p class="para"> Display source with comments and whitespace stripped. </p> <blockquote class="note"><p><strong class="note">Note</strong>: <p class="para"> This option does not work together with the <strong class="option unknown">-r</strong> option. </p> </p></blockquote> </td> </tr> <tr> <td>-z</td> <td>--zend-extension</td> <td> <p class="para"> Load Zend extension. If only a filename is given, PHP tries to load this extension from the current default library path on your system (usually <var class="filename">/etc/ld.so.conf</var> on Linux systems, for example). Passing a filename with an absolute path will not use the system's library search path. A relative filename including directory information will tell PHP to try loading the extension relative to the current directory. </p> </td> </tr> <tr> <td class="empty"> </td> <td>--ini</td> <td> <p class="para"> Show configuration file names and scanned directories. Available as of PHP 5.2.3. <div class="example" id="example-370"> <p><strong>Example #6 <em>--ini</em> example</strong></p> <div class="example-contents"> <div class="shellcode"><pre class="shellcode">$ php --ini Configuration File (php.ini) Path: /usr/dev/php/5.2/lib Loaded Configuration File: /usr/dev/php/5.2/lib/php.ini Scan for additional .ini files in: (none) Additional .ini files parsed: (none)</pre> </div> </div> </div> </p> </td> </tr> <tr> <td>--rf</td> <td>--rfunction</td> <td> <p class="para"> Show information about the given function or class method (e.g. number and name of the parameters). Available as of PHP 5.1.2. </p> <p class="para"> This option is only available if PHP was compiled with <a href="book.reflection.html" class="link">Reflection</a> support. </p> <p class="para"> <div class="example" id="example-371"> <p><strong>Example #7 basic <em>--rf</em> usage</strong></p> <div class="example-contents"> <div class="shellcode"><pre class="shellcode">$ php --rf var_dump Function [ <internal> public function var_dump ] { - Parameters [2] { Parameter #0 [ <required> $var ] Parameter #1 [ <optional> $... ] } }</pre> </div> </div> </div> </p> </td> </tr> <tr> <td>--rc</td> <td>--rclass</td> <td> <p class="para"> Show information about the given class (list of constants, properties and methods). Available as of PHP 5.1.2. </p> <p class="para"> This option is only available if PHP was compiled with <a href="book.reflection.html" class="link">Reflection</a> support. </p> <p class="para"> <div class="example" id="example-372"> <p><strong>Example #8 <em>--rc</em> example</strong></p> <div class="example-contents"> <div class="shellcode"><pre class="shellcode">$ php --rc Directory Class [ <internal:standard> class Directory ] { - Constants [0] { } - Static properties [0] { } - Static methods [0] { } - Properties [0] { } - Methods [3] { Method [ <internal> public method close ] { } Method [ <internal> public method rewind ] { } Method [ <internal> public method read ] { } } }</pre> </div> </div> </div> </p> </td> </tr> <tr> <td>--re</td> <td>--rextension</td> <td> <p class="para"> Show information about the given extension (list of <var class="filename">php.ini</var> options, defined functions, constants and classes). Available as of PHP 5.1.2. </p> <p class="para"> This option is only available if PHP was compiled with <a href="book.reflection.html" class="link">Reflection</a> support. </p> <p class="para"> <div class="example" id="example-373"> <p><strong>Example #9 <em>--re</em> example</strong></p> <div class="example-contents"> <div class="shellcode"><pre class="shellcode">$ php --re json Extension [ <persistent> extension #19 json version 1.2.1 ] { - Functions { Function [ <internal> function json_encode ] { } Function [ <internal> function json_decode ] { } } }</pre> </div> </div> </div> </p> </td> </tr> <tr> <td>--rz</td> <td>--rzendextension</td> <td> <p class="para"> Show the configuration information for the given Zend extension (the same information that is returned by <span class="function"><a href="function.phpinfo.html" class="function">phpinfo()</a></span>). Available as of PHP 5.4.0. </p> </td> </tr> <tr> <td>--ri</td> <td>--rextinfo</td> <td> <p class="para"> Show the configuration information for the given extension (the same information that is returned by <span class="function"><a href="function.phpinfo.html" class="function">phpinfo()</a></span>). Available as of PHP 5.2.2. The core configuration information is available using "main" as extension name. </p> <p class="para"> <div class="example" id="example-374"> <p><strong>Example #10 <em>--ri</em> example</strong></p> <div class="example-contents"> <div class="shellcode"><pre class="shellcode">$ php --ri date date date/time support => enabled "Olson" Timezone Database Version => 2009.20 Timezone Database => internal Default timezone => Europe/Oslo Directive => Local Value => Master Value date.timezone => Europe/Oslo => Europe/Oslo date.default_latitude => 59.930972 => 59.930972 date.default_longitude => 10.776699 => 10.776699 date.sunset_zenith => 90.583333 => 90.583333 date.sunrise_zenith => 90.583333 => 90.583333</pre> </div> </div> </div> </p> </td> </tr> </tbody> </table> </p> <blockquote class="note"><p><strong class="note">Note</strong>: <p class="para"> Options <em>-rBRFEH</em>, <em>--ini</em> and <em>--r[fcezi]</em> are available only in <acronym title="Command Line Interpreter/Interface">CLI</acronym>. </p> </p></blockquote> </div><hr /><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="features.commandline.differences.html">Differences to other SAPIs</a></div> <div class="next" style="text-align: right; float: right;"><a href="features.commandline.usage.html">Usage</a></div> <div class="up"><a href="features.commandline.html">Command line usage</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div></body></html>