PHP sapi,cli sapi,cgi SAPI
Http://www.cnblogs.com/yjf512/p/3482040.html
First question: Execute at the command line: Php-r ' echo 12; '
The console will print 12;
This is not a wonderful process, I typed in the shell command, but the PHP script is executed. The output from the execution of the PHP script will also be output at the console.
There must be an interface between this shell command (console command) and PHP, which translates the shell's parameters, code, and so on into PHP, and then translates the output of PHP into the output of the shell. This interface is called SAPI (Server application programimg Interface). It is equivalent to the PHP external environment of the agent.
So because PHP can be applied to the terminal, but also can be applied to the Web server, so, the application of SAPI on the terminal is called the CLI SAPI, applied in the Web server is called CGI SAPI. Install PHP under Windows you will see two exe:php.exe and Php-cgi.exe this corresponds to these two kinds of SAPI. For example, using PHP-V on the console, you will find that PHP version information has a (CLI) flag, which means that your PHP application here is using the CLI SAPI.
About the CLI SAPI: The manual has a very detailed description: http://php.net/manual/zh/features.commandline.php