1php(1)                        Scripting Language                        php(1)
2
3
4

NAME

6       php - PHP Command Line Interface 'CLI'
7
8       php-cgi - PHP Common Gateway Interface 'CGI' command
9

SYNOPSIS

11       php [options] [ -f ] file [[--] args...]
12
13       php [options] -r code [[--] args...]
14
15       php [options] [-B begin_code] -R code [-E end_code] [[--] args...]
16
17       php [options] [-B begin_code] -F file [-E end_code] [[--] args...]
18
19       php [options] -- [ args...]
20
21       php [options] -a
22
23       php [options] -S addr:port [-t docroot]
24

DESCRIPTION

26       PHP  is  a widely-used general-purpose scripting language that is espe‐
27       cially suited for Web development and can be embedded into  HTML.  This
28       is the command line interface that enables you to do the following:
29
30       You  can  parse and execute files by using parameter -f followed by the
31       name of the file to be executed.
32
33       Using parameter -r you can directly execute  PHP  code  simply  as  you
34       would do inside a .php file when using the eval() function.
35
36       It  is  also  possible to process the standard input line by line using
37       either the parameter -R or -F. In this mode each  separate  input  line
38       causes  the code specified by -R or the file specified by -F to be exe‐
39       cuted.  You can access the input line by $argn.  While  processing  the
40       input  lines  $argi  contains  the number of the actual line being pro‐
41       cessed. Further more the parameters -B and -E can be  used  to  execute
42       code  (see -r) before and after all input lines have been processed re‐
43       spectively. Notice that the input is  read  from  STDIN  and  therefore
44       reading  from STDIN explicitly changes the next input line or skips in‐
45       put lines.
46
47       PHP also contains an built-in web server  for  application  development
48       purpose.  By  using  the -S option where addr:port point to a local ad‐
49       dress and port PHP will listen to HTTP requests  on  that  address  and
50       port  and serve files from the current working directory or the docroot
51       passed by the -t option.
52
53       If a PHP file is provided to the command line  when  the  built-in  web
54       server  is used, it will be used as the router script. This script will
55       be started at each HTTP request. The script output is returned  to  the
56       browser,  unless  the router script returns the false value. If so, the
57       built-in server falls back to the default behaviour, returning the  re‐
58       quested resource as-is by looking up the files relative to the document
59       root specified by the -t option, if provided.
60
61       If none of -r -f -B -R -F -E or -S is present but a single parameter is
62       given then this parameter is taken as the filename to parse and execute
63       (same as with -f). If no parameter is present then the  standard  input
64       is read and executed.
65

OPTIONS

67       --interactive
68       -a             Run  PHP  interactively. This lets you enter snippets of
69                      PHP code that directly get executed. When readline  sup‐
70                      port  is  enabled  you  can edit the lines and also have
71                      history support.
72
73       --bindpath address:port|port
74       -b address:port|port
75                      Bind Path for external FASTCGI Server mode (CGI only).
76
77       --no-chdir
78       -C             Do not chdir to the script's directory (CGI only).
79
80       --no-header
81       -q             Quiet-mode. Suppress HTTP header output (CGI only).
82
83       --timing count
84       -T count       Measure execution time of script  repeated  count  times
85                      (CGI only).
86
87       --php-ini path|file
88       -c path|file   Look  for  php.ini file in the directory path or use the
89                      specified file
90
91       --no-php-ini
92       -n             No php.ini file will be used
93
94       --define foo[=bar]
95       -d foo[=bar]   Define INI entry foo with value bar
96
97       -e             Generate extended information for debugger/profiler
98
99       --file file
100       -f file        Parse and execute file
101
102       --help
103       -h             This help
104
105       --hide-args
106       -H             Hide script name (file) and  parameters  (args...)  from
107                      external  tools.  For  example  you may want to use this
108                      when a php script is started as a daemon and the command
109                      line contains sensitive data such as passwords.
110
111       --info
112       -i             PHP information and configuration
113
114       --syntax-check
115       -l             Syntax check only (lint)
116
117       --modules
118       -m             Show compiled in modules
119
120       --run code
121       -r code        Run PHP code without using script tags '<?..?>'
122
123       --process-begin code
124       -B begin_code  Run PHP begin_code before processing input lines
125
126       --process-code code
127       -R code        Run PHP code for every input line
128
129       --process-file file
130       -F file        Parse and execute file for every input line
131
132       --process-end code
133       -E end_code    Run PHP end_code after processing all input lines
134
135       --syntax-highlight
136       -s             Output HTML syntax highlighted source
137
138       --server addr:port
139       -S addr:port   Start built-in web server on the given local address and
140                      port
141
142       --docroot docroot
143       -t docroot     Specify the document root to be used by the built-in web
144                      server
145
146       --version
147       -v             Version number
148
149       --strip
150       -w             Output source with stripped comments and whitespace
151
152       --zend-extension file
153       -z file        Load Zend extension file
154
155       args...        Arguments passed to script. Use '--' args when first ar‐
156                      gument starts with '-' or script is read from stdin
157
158       --rfunction    name
159       --rf           name Shows information about function name
160
161       --rclass       name
162       --rc           name Shows information about class name
163
164       --rextension   name
165       --re           name Shows information about extension name
166
167       --rzendextension
168                      name
169       --rz           name Shows information about Zend extension name
170
171       --rextinfo     name
172       --ri           name Shows configuration for extension name
173
174       --ini          Show configuration file names
175

FILES

177       php-cli.ini    The configuration file for the CLI version of PHP.
178
179       php.ini        The standard configuration file will only be  used  when
180                      php-cli.ini cannot be found.
181

EXAMPLES

183       php -r 'echo "Hello World\n";'
184            This command simply writes the text "Hello World" to standard out.
185
186       php -r 'print_r(gd_info());'
187            This  shows  the  configuration  of your gd extension. You can use
188            this to easily check which image formats you can use. If you  have
189            any dynamic modules you may want to use the same ini file that php
190            uses when executed from your webserver. There are more  extensions
191            which have such a function. For dba use:
192            php -r 'print_r(dba_handlers(1));'
193
194       php -R 'echo strip_tags($argn)."\n";'
195            This PHP command strips off the HTML tags line by line and outputs
196            the result. To see how it works you can first look at the  follow‐
197            ing PHP command ´php -d html_errors=1 -i´ which uses PHP to output
198            HTML formatted configuration  information.  If  you  then  combine
199            those two ´php ...|php ...´ you'll see what happens.
200
201       php -E 'echo "Lines: $argi\n";'
202            Using this PHP command you can count the lines being input.
203
204       php -R '@$l+=count(file($argn));' -E 'echo "Lines:$l\n";'
205            In  this  example  PHP  expects  each  input line being a file. It
206            counts all lines of the files specified by  each  input  line  and
207            shows the summarized result.  You may combine this with tools like
208            find and change the php scriptlet.
209
210       php -R 'echo "$argn\n"; fgets(STDIN);'
211            Since you have access to STDIN from within -B -R -F and -E you can
212            skip  certain  input  lines  with your code. But note that in such
213            cases $argi only counts the lines being processed by  php  itself.
214            Having read this you will guess what the above program does: skip‐
215            ping every second input line.
216

TIPS

218       You can use a shebang line to automatically invoke  php  from  scripts.
219       Only  the CLI version of PHP will ignore such a first line as shown be‐
220       low:
221
222              #!/bin/php
223              <?php
224               // your script
225              ?>
226

SEE ALSO

228       For a more or less complete description of PHP look here:
229       http://www.php.net/manual/
230

BUGS

232       You can view the list of known bugs or report any new bug you found at:
233       https://github.com/php/php-src/issues
234

AUTHORS

236       The PHP Group: Thies C. Arntzen, Stig Bakken, Andi Gutmans, Rasmus Ler‐
237       dorf,  Sam  Ruby,  Sascha  Schumann, Zeev Suraski, Jim Winstead, Andrei
238       Zmievski.
239
240       Additional work for the CLI sapi was done by  Edin  Kadribasic,  Marcus
241       Boerger and Johannes Schlueter.
242
243       A List of active developers can be found here:
244       http://www.php.net/credits.php
245
246       And last but not least PHP was developed with the help of a huge amount
247       of contributors all around the world.
248

VERSION INFORMATION

250       This manpage describes php, version 8.2.13.
251
253       Copyright © The PHP Group
254
255       This source file is subject to version 3.01 of the PHP license, that is
256       bundled with this package in the file LICENSE, and is available through
257       the world-wide-web at the following url:
258       https://www.php.net/license/3_01.txt
259
260       If you did not receive a copy of the PHP license and are unable to  ob‐
261       tain  it  through  the  world-wide-web,  please  send  a  note  to  li‐
262       cense@php.net so we can mail you a copy immediately.
263
264
265
266The PHP Group                        2022                               php(1)
Impressum