php(1)
π NAME π
php β the PHP Command Line Interface, aka the 'CLI' bestie π«Ά
php-cgi β the PHP Common Gateway Interface 'CGI' command
πΈ SYNOPSIS πΈ
okay so here's literally every shape this thing can take:
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
php [options] -S addr:port [-t docroot]
π¦ DESCRIPTION π¦
so PHP is this widely-used general-purpose scripting language that's especially suited for Web development and can be embedded into HTML. this manpage is about the command line interface, which lets you do all of the following π
you can parse and execute files by using the parameter -f followed by the name of the file to be executed.
using the parameter -r you can directly execute PHP code, literally just like you'd do inside a .php file when using the eval() function.
it's also possible to process the standard input line by line using either the parameter -R or -F. in this mode, each separate input line causes the code specified by -R or the file specified by -F to be executed. you can access the input line by $argn. while processing the input lines, $argi contains the number of the actual line being processed. further more, the parameters -B and -E can be used to execute code (see -r) before and after all input lines have been processed respectively. notice that the input is read from STDIN, and therefore reading from STDIN explicitly changes the next input line or skips input lines. π yes bestie, that's a real gotcha.
PHP also contains a built-in web server for application development purposes π§ by using the -S option, where addr:port point to a local address and port, PHP will listen to HTTP requests on that address and port and serve files from the current working directory or the docroot passed by the -t option.
if a PHP file is provided to the command line when the built-in web server is used, it will be used as the router script. this script will be started at each HTTP request. the script output is returned to the browser, unless the router script returns the false value. if so, the built-in server falls back to the default behaviour, returning the requested resource as-is by looking up the files relative to the document root specified by the -t option, if provided. π
if none of -r -f -B -R -F -E or -S is present but a single parameter is given, then this parameter is taken as the filename to parse and execute (same as with -f). if no parameter is present, then the standard input is read and executed.
β¨ OPTIONS β¨
like, all of them. every single one. no skipping π
-a,--interactiveβ run PHP interactively. this lets you enter snippets of PHP code that directly get executed. when readline support is enabled you can edit the lines and also have history support. main character REPL energy π-baddress:port|port,--bindpathaddress:port|portβ bind path for external FASTCGI Server mode (CGI only).-C,--no-chdirβ do notchdirto the script's directory (CGI only).-q,--no-headerβ quiet-mode. suppress HTTP header output (CGI only).-Tcount,--timingcountβ measure execution time of script repeatedcounttimes (CGI only).-cpath|file,--php-inipath|fileβ look forphp.inifile in the directorypathor use the specifiedfile.-n,--no-php-iniβ nophp.inifile will be used. raw. unfiltered. π-dfoo[=bar],--definefoo[=bar]β define INI entryfoowith valuebar.-eβ generate extended information for debugger/profiler.-ffile,--filefileβ parse and executefile.-h,--helpβ this help.-H,--hide-argsβ hide script name (file) and parameters (args...) from external tools. for example you may want to use this when a php script is started as a daemon and the command line contains sensitive data such as passwords. π protect the secrets bestie-i,--infoβ PHP information and configuration.-l,--syntax-checkβ syntax check only (lint).-m,--modulesβ show compiled in modules.-rcode,--runcodeβ run PHP code without using script tags'<?..?>'.-Bbegin_code,--process-begincodeβ run PHPbegin_codebefore processing input lines.-Rcode,--process-codecodeβ run PHPcodefor every input line.-Ffile,--process-filefileβ parse and executefilefor every input line.-Eend_code,--process-endcodeβ run PHPend_codeafter processing all input lines.-s,--syntax-highlightβ output HTML syntax highlighted source.-Saddr:port,--serveraddr:portβ start built-in web server on the given local address and port.-tdocroot,--docrootdocrootβ specify the document root to be used by the built-in web server.-v,--versionβ version number.-w,--stripβ output source with stripped comments and whitespace.-zfile,--zend-extensionfileβ load Zend extensionfile.args...β arguments passed to script. use'--' argswhen first argument starts with'-'or script is read from stdin.--rfname,--rfunctionnameβ shows information about functionname.--rcname,--rclassnameβ shows information about classname.--rename,--rextensionnameβ shows information about extensionname.--rzname,--rzendextensionnameβ shows information about Zend extensionname.--riname,--rextinfonameβ shows configuration for extensionname.--iniβ show configuration file names.
π FILES π
/etc/php/@PHP_MAJOR_VERSION@.@PHP_MINOR_VERSION@/cli/php.iniβ the configuration file for the CLI version of PHP./etc/php/@PHP_MAJOR_VERSION@.@PHP_MINOR_VERSION@/cgi/php.iniβ the configuration file for the CGI version of PHP./etc/php/@PHP_MAJOR_VERSION@.@PHP_MINOR_VERSION@/apache2/php.iniβ the configuration file for the version of PHP that apache2 uses.
π EXAMPLES π
okay these are so fun, watch this π
php -r 'echo "Hello World\n";'
this command simply writes the text "Hello World" to standard out. iconic first move, honestly.
php -r 'print_r(gd_info());'
this shows the configuration of your gd extension. you can use this to easily check which image formats you can use. if you have any dynamic modules you may want to use the same ini file that php uses when executed 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 you can first look at the following PHP command Β΄php -d html_errors=1 -iΒ΄ which uses PHP to output HTML formatted configuration information. if you then combine those two Β΄php ...|php ...Β΄ you'll see what happens. π the pipeline ate
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 by each input line and shows the summarized result. you may combine this with tools like find and change the php scriptlet. slay.
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 your code. but note that in such cases $argi only counts the lines being processed by php itself. having read this you will guess what the above program does: skipping every second input line. π it's giving sneaky
π TIPS π
you can use a shebang line to automatically invoke php from scripts. only the CLI version of PHP will ignore such a first line as shown below:
#!/bin/php
<?php
// your script
?>
π«Ά SEE ALSO π«Ά
for a more or less complete description of PHP look here: http://www.php.net/manual/
π BUGS π
you can view the list of known bugs or report any new bug you found at: https://github.com/php/php-src/issues
π AUTHORS π
The PHP Group: Thies C. Arntzen, Stig Bakken, Andi Gutmans, Rasmus Lerdorf, Sam Ruby, Sascha Schumann, Zeev Suraski, Jim Winstead, Andrei Zmievski.
additional work for the CLI sapi was done by Edin Kadribasic, Marcus Boerger and Johannes Schlueter.
a List of active developers can be found here: http://www.php.net/credits.php
and last but not least PHP was developed with the help of a huge amount of contributors all around the world. π the community really said "we all built this" and honestly? true.
β VERSION INFORMATION β
this manpage describes php, version 8.3.6.
π COPYRIGHT π
Copyright Β© The PHP Group
this source file is subject to version 3.01 of the PHP license, that is bundled with this package in the file LICENSE, and is available through the world-wide-web at the following url: https://www.php.net/license/3_01.txt
if you did not receive a copy of the PHP license and are unable to obtain it through the world-wide-web, please send a note to license@php.net so we can mail you a copy immediately. π«Ά
and that's the whole page bestie β brought to you by The PHP Group, dated 2024, for php(1). mwah πβ¨
π¦ where this page comes from
- ubuntu noble: php8.3-cli 8.3.6-0maysync1
- ubuntu noble: php8.3-cli 8.3.6-0ubuntu0.24.04.11
- ubuntu noble: php8.3-cli 8.3.6-0ubuntu0.24.04.13
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms