php(1)

๐Ÿ“ฆ version 8.3.36, in arch rolling

๐Ÿ’– 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 -f followed by the name of the file to be executed. slay.
  • 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. same energy fr.
  • it's also possible to process 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 via $argn. while processing the input lines, $argi holds 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 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 -S option, where addr:port points 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 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 -t option, if provided.
  • and if none of -r -f -B -R -F -E or -S is 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, repeated count times (CGI only).
  • --php-ini path|file, -c path|file โ€” look for php.ini file in the directory path, or use the specified file.
  • --no-php-ini, -n โ€” no php.ini file will be used. raw. unbothered. unconfigured.
  • --define foo[=bar], -d foo[=bar] โ€” define INI entry foo with value bar.
  • -e โ€” generate extended information for debugger/profiler.
  • --file file, -f file โ€” parse and execute file.
  • --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 PHP begin_code before processing input lines.
  • --process-code code, -R code โ€” run PHP code for every input line.
  • --process-file file, -F file โ€” parse and execute file for every input line.
  • --process-end code, -E end_code โ€” run PHP end_code after 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 '--' args when 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 function name.
  • --rclass name, --rc name โ€” shows information about class name.
  • --rextension name, --re name โ€” shows information about extension name.
  • --rzendextension name, --rz name โ€” shows information about Zend extension name.
  • --rextinfo name, --ri name โ€” shows configuration for extension name.
  • --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 when php-cli.ini cannot 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 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. 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 like find and change the php scriptlet. lowkey powerful.
  • 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. 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 ยฉ 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