php(1)

πŸ“¦
version 8.5.9 Β· 2 versions
, in ubuntu stonking

πŸ’– php(1) β€” the manual page, but make it a group chat πŸ’–

okay bestie, you found the php(1) man page and let me tell you, this one is iconic. this is the doc for php β€” the PHP Command Line Interface 'CLI' β€” and also its sibling php-cgi, the PHP Common Gateway Interface 'CGI' command. two for the price of one, no cap. 🫢


✨ NAME ✨

  • php β€” PHP Command Line Interface 'CLI' πŸ’…
  • php-cgi β€” PHP Common Gateway Interface 'CGI' command πŸ¦‹

✨ SYNOPSIS ✨

like, here's literally how you call it:

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 a wildly-used general-purpose scripting language, and it's especially slay for Web development, and it can be embedded into HTML. that's the vibe. πŸ’œ

this thing right here is the command line interface, and here's everything it lets you do:

  • you can parse and execute files with the parameter -f followed by the name of the file you wanna execute. simple as that.
  • with the parameter -r you can directly execute PHP code, exactly like you'd do inside a .php file when you use the eval() function. straight into it, no script tags needed.
  • you can also process the standard input line by line using either -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 grab the input line with $argn. and while it's chewing through input lines, $argi holds the number of the actual line being processed. also: the parameters -B and -E can run code (see -r) before and after all input lines have been processed, respectively. πŸ‘‘
ok important heads-up bestie: the input is read from STDIN, so if you read from STDIN explicitly, you change the next input line or skip input lines. the way that changes everything. 😭
  • PHP also has a built-in web server for application development purposes. using the -S option, where addr:port points to a local address and port, PHP will listen for HTTP requests on that address and port and serve files from the current working directory, or from the docroot you pass with the -t option. 🧚
  • if you hand a PHP file to the command line while the built-in web server is running, that file becomes the router script. this script gets started on every single HTTP request. its output goes back to the browser β€” unless the router script returns the false value. and if it does return false? the built-in server falls back to its default behaviour and returns the requested resource as-is, by looking up the files relative to the document root you specified with the -t option, if you gave one. 🌸
  • and if none of -r, -f, -B, -R, -F, -E or -S is present, but you did give a single parameter, then that parameter is taken as the filename to parse and execute (same as with -f). and if there's no parameter at all, then standard input is read and executed. periodt. πŸ’–

✨ OPTIONS ✨

here's the whole menu, no skips, no cuts, we're doing all of them:

  • --interactive, -a β€” run PHP interactively. this lets you drop in snippets of PHP code that get executed immediately. when readline support is enabled you can edit the lines and you get history support. chef's kiss. πŸŽ€
  • --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).
  • --timing count, -T count β€” measure execution time of script repeated count times (CGI only).
  • --php-ini path|file, -c path|file β€” look for the php.ini file in the directory path, or use the specified file.
  • --no-php-ini, -n β€” no php.ini file will be used at all. feral behaviour but ok. πŸ’€
  • --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 hello you're welcome 🫢
  • --hide-args, -H β€” hide script name (file) and parameters (args...) from external tools. for example you may want this when a php script is started as a daemon and the command line contains sensitive data such as passwords. protect the secrets bestie πŸ”
  • --info, -i β€” PHP information and configuration.
  • --syntax-check, -l β€” syntax check only (lint). is it valid though, that's the question ✨
  • --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 πŸ’…
  • --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 when the script is read from stdin.
  • --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 ✨

  • /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.
ngl the source of this section is giving mangled roff markup energy (+.B, +.TP wandering around like they own the place πŸ™ˆ) but the three paths and their descriptions above are the whole content, fr fr.

✨ EXAMPLES ✨

a lil show-and-tell, because examples ate and left no crumbs:

php -r 'echo "Hello World\n";'

this command simply writes the text Hello World to standard out. iconic, simple, timeless. 🌟

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. 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. main character energy, honestly. πŸ‘‘


✨ 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:


✨ BUGS ✨

you can view the list of known bugs or report any new bug you found at:

not me telling you to go file that bug you just found πŸ› go go go

✨ 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:

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 and it ate. πŸŒπŸ’–


✨ VERSION INFORMATION ✨

this manpage describes php, version 8.5.9. ✨


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:

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, from the php(1) manual. go forth and <rainbow>run some code</rainbow> πŸ’…βœ¨πŸŽ€

πŸ“¦ where this page comes from