php(1)
π NAME π
php β the PHP Command Line Interface, aka the 'CLI' bestie, and php-cgi β the PHP Common Gateway Interface, aka the 'CGI' command β¨
Both of these live in section 1 of the manual, so when you're out here saying "php(1)" you're naming the Scripting Language page, and yeah, this is it. π«Ά
π SYNOPSIS π
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 πΈ
okay so, PHP is a widely-used general-purpose scripting language that is especially suited for Web development, and lowkey it can also be embedded into HTML. Obsessed. This here is the command line interface, and it lets you do all of the following:
- You can parse and execute files by using the parameter
-ffollowed by the name of the file you want executed. π - Using the parameter
-ryou can directly execute PHP code, simply as you would do inside a.phpfile when using theeval()function. It's giving "instant gratification". - It is also possible to process the standard input line by line using either the parameter
-Ror-F. In this mode each separate input line causes the code specified by-Ror the file specified by-Fto be executed. You can access the input line by$argn. While processing the input lines,$argicontains the number of the actual line being processed. Furthermore the parameters-Band-Ecan be used to execute code (see-r) before and after all input lines have been processed, respectively. Notice that the input is read fromSTDINand therefore reading fromSTDINexplicitly changes the next input line or skips input lines. π¦ (yes that's a real gotcha, bestie, not me being dramatic.) - PHP also contains a built-in web server for application development purposes. By using the
-Soption whereaddr:portpoint 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-toption. localhost era, slay. - If none of
-r-f-B-R-F-Eor-Sis 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 β¨
--interactive,-aβ 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. π--bindpathaddress:port|port,-baddress:port|port β Bind Path for external FASTCGI Server mode (CGI only).--no-chdir,-Cβ Do notchdirto the script's directory (CGI only).--no-header,-qβ Quiet-mode. Suppress HTTP header output (CGI only). π€«--timingcount,-Tcount β Measure execution time of script repeated count times (CGI only). β±οΈ--php-inipath|file,-cpath|file β Look forphp.inifile in the directory path or use the specified file.--no-php-ini,-nβ Nophp.inifile will be used. (chaos mode, but make it official π )--definefoo[=bar],-dfoo[=bar] β Define INI entry foo with value bar.-eβ Generate extended information for debugger/profiler. π--filefile,-ffile β Parse and execute file.--help,-hβ This help. π«Ά--hide-args,-Hβ 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. π--info,-iβ PHP information and configuration.--syntax-check,-lβ Syntax check only (lint). β--modules,-mβ Show compiled in modules.--runcode,-rcode β Run PHP code without using script tags'<?..?>'.--process-begincode,-Bbegin_code β Run PHP begin_code before processing input lines.--process-codecode,-Rcode β Run PHP code for every input line.--process-filefile,-Ffile β Parse and execute file for every input line.--process-endcode,-Eend_code β Run PHP end_code after processing all input lines.--syntax-highlight,-sβ Output HTML syntax highlighted source. π--serveraddr:port,-Saddr:port β Start built-in web server on the given local address and port.--docrootdocroot,-tdocroot β Specify the document root to be used by the built-in web server.--version,-vβ Version number.--strip,-wβ Output source with stripped comments and whitespace.--zend-extensionfile,-zfile β Load Zend extension file.args...β Arguments passed to script. Use'--' argswhen first argument starts with'-'or script is read from stdin.--rfunctionname,--rfname β Shows information about function name.--rclassname,--rcname β Shows information about class name.--rextensionname,--rename β Shows information about extension name.--rzendextensionname,--rzname β Shows information about Zend extension name.--rextinfoname,--riname β Shows configuration for extension name.--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 π
php -r 'echo "Hello World\n";'
This command simply writes the text "Hello World" to standard out. iconic first step, fr fr. β¨
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. π¦
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.
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. π sneaky but valid.
π 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: http://bugs.php.net
π 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. ππ«Ά total main character energy from everyone involved.
β VERSION INFORMATION β
This manpage describes php, version 8.1.2-1ubuntu2.28.
π 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 β¨ this one's brought to you by The PHP Group, dated 2021, filed under php(1) β go forth and -r responsibly π
ππ¦
π¦ where this page comes from
- ubuntu jammy: php8.1-cli 8.1.2-1ubuntu2.28
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms