Linux "php7.2" Command Line Options and Examples
PHP Command Line Interface 'CLI'

PHP is a widely-used general-purpose scripting language that is especially suited for Web development and can be embedded into HTML. This is the command line interface that enables you to do the following: You can parse and execute files by using parameter -f followed by the name of the file to be executed.


Usage:

php [options] [ -f ] file [[--] args...]




Command Line Options:

--bindpath
address:port|port
php7.2 --bindpath ...
-b
Bind Path for external FASTCGI Server mode (CGI only).
php7.2 -b ...
-C
Do not chdir to the script's directory (CGI only).
php7.2 -C ...
-q
Quiet-mode. Suppress HTTP header output (CGI only).
php7.2 -q ...
-T
count Measure execution time of script repeated count times (CGI only).
php7.2 -T ...
-c
path|file Look for php.ini file in the directory path or use the specified file
php7.2 -c ...
-n
No php.ini file will be used
php7.2 -n ...
-d
foo[=bar] Define INI entry foo with value bar
php7.2 -d ...
-e
Generate extended information for debugger/profiler
php7.2 -e ...
-f
file Parse and execute file
php7.2 -f ...
-i
PHP information and configuration
php7.2 -i ...
-l
Syntax check only (lint)
php7.2 -l ...
-m
Show compiled in modules
php7.2 -m ...
-r
code Run PHP code without using script tags '<?..?>'
php7.2 -r ...
-B
begin_code Run PHP begin_code before processing input lines
php7.2 -B ...
-R
code Run PHP code for every input line
php7.2 -R ...
-F
file Parse and execute file for every input line
php7.2 -F ...
-E
end_code Run PHP end_code after processing all input lines
php7.2 -E ...
-s
Output HTML syntax highlighted source
php7.2 -s ...
-S
addr:port Start built-in web server on the given local address and port
php7.2 -S ...
-t
docroot Specify the document root to be used by the built-in web server
php7.2 -t ...
-w
Output source with stripped comments and whitespace
php7.2 -w ...
-z
args... Arguments passed to script. Use '--' args when first argument starts with '-' or script is readfrom stdin
php7.2 -z ...
--rf
name Shows information about function name
php7.2 --rf ...
--rc
name Shows information about class name
php7.2 --rc ...
--re
name Shows information about extension name
php7.2 --re ...
--rz
name Shows information about Zend extension name
php7.2 --rz ...
--ri
name Shows configuration for extension name
php7.2 --ri ...
--ini
FILES/etc/php/@PHP_MAJOR_VERSION@.@PHP_MINOR_VERSION@/cli/php.iniThe configuration file for the CLI version of PHP./etc/php/@PHP_MAJOR_VERSION@.@PHP_MINOR_VERSION@/cgi/php.iniThe configuration file for the CGI version of PHP./etc/php/@PHP_MAJOR_VERSION@.@PHP_MINOR_VERSION@/apache2/php.iniThe configuration file for the version of PHP that apache2 uses.EXAMPLESphp -r 'echo "Hello World\n";'This command simply writes the text "Hello World" to standard out.php -r 'print_r(gd_info());'This shows the configuration of your gd extension. You can use this to easily check which image formatsyou can use. If you have any dynamic modules you may want to use the same ini file that php uses whenexecuted from your webserver. There are more extensions which have such a function. For dba use:php -r 'print_r(dba_handlers(1));'php -R 'echo strip_tags($argn)."\n";'This PHP command strips off the HTML tags line by line and outputs the result. To see how it works youcan first look at the following PHP command ´php -d html_errors=1 -i´ which uses PHP to output HTML for‐matted configuration information. If you then combine those two ´php ...|php ...´ you'll see what hap‐pens.php -E 'echo "Lines: $argi\n";'Using this PHP command you can count the lines being input.php -R '@$l+=count(file($argn));' -E 'echo "Lines:$l\n";'In this example PHP expects each input line being a file. It counts all lines of the files specified byeach input line and shows the summarized result. You may combine this with tools like find and changethe php scriptlet.php -R 'echo "$argn\n"; fgets(STDIN);'Since you have access to STDIN from within -B -R -F and -E you can skip certain input lines with yourcode. But note that in such cases $argi only counts the lines being processed by php itself. Having readthis you will guess what the above program does: skipping every second input line.TIPSYou can use a shebang line to automatically invoke php from scripts. Only the CLI version of PHP will ignoresuch a first line as shown below:#!/bin/php<?php// your script?>
php7.2 --ini ...