See full name to know, PHP-CLI is the short name of PHP command line interface, that is, the PHP interface, in Windows and Linux are supported PHP-CLI mode, in fact, both, I have written before:
One, window run the PHP program at the command line
Second, Linux uses crontab to achieve timed tasks
Advantages and application of PHP-CLI mode:
- 1. Fully support multithreading
- 2. As above, can achieve the scheduled task
- 3. Developing desktop apps is using PHP-CLI and GTK packages
- Write shell scripts in PHP 4.linux
In fact, PHP operating environment far more than Apache and CLI, haha, such as 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 detect, do not believe, look at the following code:
- <? PHP
- /** reprint Please indicate the link: http://www.phpddt.com * *
- echo Php_sapi_name();
I run the results on the browser:
I run on the cmd of Windows:
Use standard input and output:
STDIN Standard input device
STDOUT Standard output device
STDERR standard error device
Look at the results of running the following program:
- <? PHP
- Ask for input
- Fwrite(STDOUT, "Enter Your Name:");
- Get input
- $name = trim(fgets(STDIN));
- Write input back
- Fwrite(STDOUT, "Hello, $name!") );
Run:
Use the command-line arguments:
The PHP CLI has two special variables for this purpose: one is the $ARGV variable, which saves the arguments passed to the PHP script as a separate array element through the command line, and the $ ARGC variable, which is used to hold the number of elements in the $ARGV array.
You can run:
- <? PHP
- /**
- * @link http://www.phpddt.com
- */
- Print_r($argv);
Look at the results:
Use the PHP CLI to pass the script parameters in the form:
Please see the parameters:
Parameters |
Description |
-A |
Running run interactively interactively |
-C |
Path reads PHP's. ini file from path |
-N |
Run directly without reading PHP's. ini file |
-M |
List the compiled modules |
-I. |
Display information about PHP builds |
-L |
Check the syntax of the PHP script |
-S |
Display the source code in a colored fashion |
-W |
Display the source code after removing the comment |
-H |
Show Help
|
At this point, I have a certain understanding of the PHP cli, if the reader wants to know more, please refer to the official manual: http://php.net/manual/zh/features.commandline.php
Reprint: http://www.phpddt.com/php/php-cli.html Respect others ' labor achievement is respect oneself!
PHP CLI Mode Introduction and use Tutorial