Look at the full name to know, php-cli is phpCommandLineInterface abbreviation, that is, PHP command line interface, in windows and linux are support PHP-CLI mode, in fact, the two, I used to write text
Look at the full name to know, php-cli is php Command Line Interface short, that is, PHP Command Line Interface, in windows and linux are support PHP-CLI mode, in fact, the two, I have written articles before:
I. window: run the php program in the command line.
II. use crontab in linux to implement scheduled tasks
Advantages and application of PHP-CLI mode:
- 1. multithreading is fully supported.
- 2. as shown above, you can implement scheduled tasks.
- 3. developing desktop applications is using PHP-CLI and GTK packages
- 4. use php to write shell scripts in linux
In fact, the PHP runtime environment is far more than apache and cli, haha, such
Aolserver, apache, apache2filter, apache2handler, caudium, cgi (until PHP 5.3), cgi-fcgi, cli, continuity, embed, isapi, litespeed, milter, nsapi, phttpd, pi3web, roxen, thttpd, tux, and webjames.
You can use php_sapi_name () to check the code:
I run the result on the browser:
On windows cmd, I run:
Use standard input and output:
STDINStandard input device
STDOUTStandard output device
STDERRStandard error device
You can see the result of running the following program:
Run:
Use the command line independent variable:
Php cli has two special variables to achieve this purpose: one is the $ argv variable, which saves the parameters passed to the PHP script as separate array elements through the command line; the other is the $ argc variable, which is used to save the number of elements in the $ argv array.
You can run:
Result:
Use php cli to pass script parameters:
See parameters:
Parameters |
Description |
- |
Interactive Run of Run interactively |
-C |
Path: Read the php. ini file from path. |
-N |
Run without reading the php. ini file. |
-M |
List compiled modules |
-I |
Display PHP build information |
-L |
Check the syntax of the PHP script |
-S |
Display source code in color |
-W |
Displays the source code after the annotation is removed. |
-H |
Show Help
|
So far, I have a certain understanding of PHP CLI, if readers want to learn more, please refer to the official manual: http://php.net/manual/zh/features.commandline.php