php(1)
π php(1) & php-cgi(1) β NAME π
okay so bestie, welcome to the glow-up of the PHP Command Line Interface, aka the CLI. And her sister, the CGI one. Here's the official intro:
phpβ PHP Command Line Interface 'CLI' πphp-cgiβ PHP Common Gateway Interface 'CGI' command π¦
β¨ SYNOPSIS β¨
the way you call her matters, bestie. here's every single form:
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 πΈ
PHP is a widely-used general-purpose scripting language that's especially suited for Web development and can be embedded into HTML. iconic behaviour, truly. This here is the command line interface, and it lets you do all of the following, no cap:
You can parse and execute files by using the parameter -f followed by the name of the file to be executed. π«Ά
Using parameter -r you can directly execute PHP code, simply as you would do inside a .php file when using the eval() function. β¨
It is 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, it's giving chaos, but it's documented chaos.)
PHP also contains an built-in web server for application development purpose. 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 π
every flag, every alias, zero skips. periodt.
--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. π--bindpath address:port|port,-b address: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).--timing count,-T countβ Measure execution time of script repeatedcounttimes (CGI only).--php-ini path|file,-c path|fileβ Look forphp.inifile in the directorypathor use the specifiedfile--no-php-ini,-nβ Nophp.inifile will be used--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--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. π (protect your secrets bestie!!)--info,-iβ PHP information and configuration--syntax-check,-lβ Syntax check only (lint)--modules,-mβ Show compiled in modules--run code,-r codeβ Run PHPcodewithout 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--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--zend-extension file,-z fileβ Load Zend extensionfileargs...β Arguments passed to script. Use'--' argswhen first argument starts with-or script is read from stdin--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
ngl the amount of aliases here is giving main character energy. learn the short ones, they'll save your wrists. π
π FILES π
where your config besties live:
/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 π₯
the good stuff. copy these exactly, bestie:
php -r 'echo "Hello World\n";'
This command simply writes the text "Hello World" to standard out. β
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. πβ¨
π«Ά 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: 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
not me telling you to actually file the bug report. do it bestie, the maintainers ate. π
π 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. πΈ
β VERSION INFORMATION β
This manpage describes php, version 8.4.27.
π 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 and that's the whole page bestie, go slay π
β brought to you by The PHP Group, 2024, php(1). mwah πβ¨
π¦ where this page comes from
- debian trixie: php8.4-cli 8.4.27-1~deb13u1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms