php(1)
๐ php โ the manual, but make it a group chat ๐
okay bestie, gather round, because we're talking about php, aka the PHP Command Line Interface 'CLI', and its chaotic twin php-cgi, the PHP Common Gateway Interface 'CGI' command. this is the manpage, it lives in section 1 of the manual, and no cap it's actually so useful. let's get into it ๐
โจ SYNOPSIS โจ
here's every single way you can summon this thing, verbatim, do not come for me:
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]
that's it, that's the whole menu ๐
๐ธ DESCRIPTION ๐ธ
so. PHP is a widely-used general-purpose scripting language that is especially suited for Web development and can be embedded into HTML. iconic behavior honestly ๐
this particular thing is the command line interface, which lets you do all of the following:
- you can parse and execute files by using the parameter
-ffollowed by the name of the file to be executed. slay. - using the parameter
-ryou can directly execute PHP code, literally just like you'd do inside a.phpfile when using theeval()function. same energy fr. - it's also possible to process standard input line by line using either the parameter
-Ror-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 via$argn. while processing the input lines,$argiholds the number of the actual line being processed. further more, 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 from STDIN, and therefore reading from STDIN explicitly changes the next input line or skips input lines. yes that's real, yes it's a little cursed, we move. - PHP also contains a built-in web server for application development purposes ๐ง. by using the
-Soption, whereaddr:portpoints 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. - 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
falsevalue. if it does, 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-toption, if provided. - and if none of
-r-f-B-R-F-Eor-Sis present but a single parameter is given, then that parameter is taken as the filename to parse and execute (same as with-f). and if no parameter is present at all, then the standard input is read and executed. the vibes decide, basically.
๐ OPTIONS ๐
one bullet per flag, all of them, no skipping, we don't do that here:
--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. the REPL of your dreams โจ--bindpath address:port|port,-b address:port|portโ bind path for external FASTCGI Server mode (CGI only).--no-chdir,-Cโ do not chdir to the script's directory (CGI only).--no-header,-qโ quiet-mode. suppress HTTP header output (CGI only). shhh ๐คซ--timing count,-T countโ measure execution time of script, repeatedcounttimes (CGI only).--php-ini path|file,-c path|fileโ look forphp.inifile in the directorypath, or use the specifiedfile.--no-php-ini,-nโ nophp.inifile will be used. raw. unbothered. unconfigured.--define foo[=bar],-d foo[=bar]โ define INI entryfoowith valuebar.-eโ generate extended information for debugger/profiler.--file file,-f fileโ parse and executefile.--help,-hโ this help. hi, you're here, you found it ๐ซถ--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. yes bestie, protect your secrets ๐--info,-iโ PHP information and configuration.--syntax-check,-lโ syntax check only (lint). the vibe check for your code โญ--modules,-mโ show compiled in modules.--run code,-r codeโ run PHP code without using script tags'<?..?>'.--process-begin code,-B begin_codeโ run PHPbegin_codebefore processing input lines.--process-code code,-R codeโ run PHPcodefor every input line.--process-file file,-F fileโ parse and executefilefor every input line.--process-end code,-E end_codeโ run PHPend_codeafter processing all input lines.--syntax-highlight,-sโ output HTML syntax highlighted source. pretty code is a love language ๐--server addr:port,-S addr:portโ start built-in web server on the given local address and port.--docroot docroot,-t docrootโ 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 file.args...โ arguments passed to script. use'--' argswhen the first argument starts with-or the script is read from stdin. important!! don't skip this one!!--rfunction name,--rf nameโ shows information about functionname.--rclass name,--rc nameโ shows information about classname.--rextension name,--re nameโ shows information about extensionname.--rzendextension name,--rz nameโ shows information about Zend extensionname.--rextinfo name,--ri nameโ shows configuration for extensionname.--iniโ show configuration file names.
๐ FILES ๐
php-cli.iniโ the configuration file for the CLI version of PHP.php.iniโ the standard configuration file will only be used whenphp-cli.inicannot be found. it's giving backup plan energy, and honestly? valid.
๐ EXAMPLES ๐
the glow-up section. all commands exactly as written, no notes:
php -r 'echo "Hello World\n";'this command simply writes the text "Hello World" to standard out. hello world, we love a classic ๐php -r 'print_r(gd_info());'this shows the configuration of yourgdextension. 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. chef's kiss ๐php -E 'echo "Lines: $argi\n";'using this PHP command you can count the lines being input. counting era ๐ข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 likefindand change the php scriptlet. lowkey powerful.php -R 'echo "$argn\n"; fgets(STDIN);'since you have access to STDIN from within-B-R-Fand-Eyou can skip certain input lines with your code. but note that in such cases$argionly 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. iconic. periodt.
๐ซถ 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
?>
so go forth and make your scripts executable, bestie ๐ฆ
๐ฅ SEE ALSO ๐ฅ
for a more or less complete description of PHP look here: https://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
please actually report them, not just vent in the group chat ๐
๐ 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: https://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. literally a global group project, we love to see it ๐๐
โญ VERSION INFORMATION โญ
this manpage describes php, version 8.5.12.
๐ 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.
okay that's the whole thing, you're officially php-pilled ๐ this was brought to you by The PHP Group, dated 2024, filed under <pink>php(1)</pink> in the manual โ go write something iconic, bestie, ily, bye ๐
โจ
๐ฆ where this page comes from
- arch rolling: php 8.5.12-3 ยท PHP-3.01
- fedora 44: php-cli 8.5.12-1.fc44 ยท PHP-3.01 AND Zend-2.0 AND BSD-2-Clause AND MIT AND Apache-1.0 AND Apache-2.0 AND NCSA AND PostgreSQL
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms