Command line options
Command line options
Command line options
The list of command line options provided by the
PHP binary can be queried at any time by running PHP with the
-h switch:
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>.
Option | Long Option | Description |
---|---|---|
-a | –interactive |
Run PHP interactively. For more information, see |
-b | –bindpath |
Bind Path for external FASTCGI Server mode |
-C | –no-chdir |
Do not chdir to the script’s directory |
-q | –no-header |
Quiet-mode. Suppress HTTP header output |
-T | –timing |
Measure execution time of script repeated |
-c | –php-ini |
Specifies either a directory in which to look for
$ php -c /custom/directory/ my_script.php $ php -c /custom/directory/custom-file.ini my_script.php If this option is not specified, php.ini is searched for in the default locations. |
-n | –no-php-ini |
Ignore php.ini |
-d | –define |
Set a custom value for any of the configuration -d configuration_directive[=value]
# 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" |
-e | –profile-info |
Activate the extended information mode, to be used |
-f | –file |
Parse and execute the specified file. The
|
-h and -? | –help and –usage | Output a list of command line options with one line descriptions of what they do. |
-i | –info | Calls phpinfo(), and prints out the results. If PHP is not working correctly, it is advisable to use the command php -i and see whether any error messages are printed out before or in place of the information tables. Beware that when using the CGI mode the output is in HTML and therefore very large. |
-l | –syntax-check |
Provides a convenient way to perform only a syntax This option won’t find fatal errors (like undefined
|
-m | –modules |
Example #1 Printing built in (and loaded) PHP and Zend $ php -m [PHP Modules] xml tokenizer standard session posix pcre overload mysql mbstring ctype [Zend Modules] |
-r | –run |
Allows execution of PHP included directly on the
|
-B | –process-begin |
PHP code to execute before processing stdin. Added |
-R | –process-code |
PHP code to execute for every input line. Added in There are two special variables available in this |
-F | –process-file |
PHP file to execute for every input line. Added in |
-E | –process-end |
PHP code to execute after processing the input.
Example #4 Using the -B , -R and -E options to count the number of lines $ find my_proj | php -B '$l=0;' -R '$l += count(@file($argn));' -E 'echo "Total Lines: $l\n";' Total Lines: 37328 |
-S | –server |
Starts built-in web |
-t | –docroot | Specifies document root for built-in web server. Available as of PHP 5.4.0. |
-s | –syntax-highlight and –syntax-highlighting |
Display colour syntax highlighted source. This option uses the internal mechanism to parse
|
-v | –version |
Example #5 Using -v to get the SAPI name and $ 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 |
-w | –strip |
Display source with comments and whitespace
|
-z | –zend-extension |
Load Zend extension. If only a filename is given, |
–ini |
Show configuration file names and scanned Example #6 –ini example $ 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) |
|
–rf | –rfunction |
Show information about the given function or class This option is only available if PHP was compiled
Example #7 basic –rf usage $ php --rf var_dump Function [ <internal> public function var_dump ] { - Parameters [2] { Parameter #0 [ <required> $var ] Parameter #1 [ <optional> $... ] } } |
–rc | –rclass |
Show information about the given class (list of This option is only available if PHP was compiled
Example #8 –rc example $ 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 ] { } } } |
–re | –rextension |
Show information about the given extension (list of This option is only available if PHP was compiled
Example #9 –re example $ php --re json Extension [ <persistent> extension #19 json version 1.2.1 ] { - Functions { Function [ <internal> function json_encode ] { } Function [ <internal> function json_decode ] { } } } |
–rz | –rzendextension |
Show the configuration information for the given |
–ri | –rextinfo |
Show the configuration information for the given
Example #10 –ri example $ 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 |
Note:
Options -rBRFEH, –ini and
–r[fcezi] are available only in CLI.