There are 4 common operating methods of php: CGI, FastCGI, APACHE2HANDLER, CLI.
1、CGI
CGI is a common gatewag interface. It is a program. In layman's terms, CGI is like a bridge that connects web pages and executors in WEB servers. It passes the instructions received by HTML to the server's executors, and then returns the result of the server's executors to the HTML page. CGI has excellent cross-platform performance and can be implemented on almost any operating system.
When encountering a connection request (user request), when CGI method encounters a connection request (user request), first create a CGI process, activate a CGI process, and then process the request, and end the child process after processing. This is the fork-and-execute pattern. Therefore, the number of connection requests on the server using the cgi method will be as many cgi subprocesses as the repeated loading of the child process is the main reason for the poor performance of cgi. When the number of user requests is very large, it will squeeze out the system's resources such as memory, CPU time, etc., resulting in low efficiency.
2、FastCGI
fast-cgi is an upgraded version of cgi. FastCGI is like a long-live CGI. It can be executed all the time. Once activated, it will not take time to fork once every time. PHP is managed using PHP-FPM (FastCGI Process Manager), the full name is PHP FastCGI Process Manager.
The FastCGI process manager (IIS ISAPI or Apache Module) is loaded when the Web Server starts. The FastCGI process manager itself initializes, starts multiple CGI interpreter processes (see multiple php-cgis) and waits for a connection from the Web Server.
When a client request arrives at the Web Server, the FastCGI process manager selects and connects to a CGI interpreter. Web server sends CGI environment variables and standard input to FastCGI child process php-cgi.
After the FastCGI subprocess completes processing, the standard output and error message are returned to the Web Server from the same connection. When the FastCGI child process closes the connection, the request is reported to be completed. The FastCGI child process then waits for and processes the next connection from the FastCGI process manager (running in the Web Server). In CGI mode, php-cgi exits here.
In the above case, you can imagine how slow CGI is usually. Each Web request PHP must re-parse, reload all extensions and re-initialize all data structures. With FastCGI, all of this happens only once when the process starts. An additional benefit is that the Persistent database connection can work.
3、APACHE2HANDLER
As an Apache module, after the Apache server is started, it will generate multiple process copies and reside in memory. Once a request appears, these spare child processes will be processed immediately, so that there will be no delay caused by generating child processes. These server copies do not exit immediately after processing an HTTP request, but stay in the computer and wait for the next request. Respond faster to client browser requests and perform higher.
4、CLI
Cli is the command line running mode of PHP. The running commands on the cli side are sometimes very useful. Here are a few summary:
View php version information
eric:~ youngeric$ php -v PHP 5.5.38 (cli) (built: Oct 1 2016 23:03:00) Copyright (c) 1997-2015 The PHP Group Zend Engine v2.5.0, Copyright (c) 1998-2015 Zend Technologies
Check out the current php extension
eric:~ youngeric$ php -m [PHP Modules] bcmath bz2 calendar Core ctype curl date ......
View configuration information (equivalent to using the phpinfo() function)
eric:~ youngeric$ php -ini phpinfo() PHP Version => 5.5.38 System => Darwin 16.1.0 Darwin Kernel Version 16.1.0: Wed Oct 19 20:31:56 PDT 2016; root:xnu-3789.21.4~4/RELEASE_X86_64 x86_64 Build Date => Oct 1 2016 23:01:51 Configure Command => './configure' '--prefix=/usr/local/Cellar/php55/5.5.38_11' '--localstatedir=/usr/local/var' '--sysconfdir=/usr/local/etc/php/5.5' '--with-config-file-path=/usr/local/etc/php/5.5' '--with-config-file-scan-dir=/usr/local/etc/php/5.5/' '--mandir=/usr/local/Cellar/php55/5.5.38_11/share/man' '--enable-bcmath' '--enable-calendar' '--enable-dba' '--enable-exif' '--enable-ftp' '--enable-gd-native-ttf' '--enable-mbregex' '--enable-mbstring' '--enable-shmop' '--enable-soap' '--enable-sockets' '--enable-sysvmsg' '--enable-sysvsem' '--enable-sysvshm' '--enable-wddx' '--enable-zip' '--with-freetype-dir=/usr/local/opt/freetype' '--with-gd' '--with-gettext=/usr/local/opt/gettext' '--with-iconv-dir=/usr' '--with-icu-dir=/usr/local/opt/icu4c' '--with-jpeg-dir=/usr/local/opt/jpeg' '--with-kerberos=/usr' '--with-libedit' '--with-mhash' '--with-ndbm=/usr' '--with-png-dir=/usr/local/opt/libpng' '--with-xmlrpc' '--with-zlib=/usr' '--with-readline=/usr/local/opt/readline' '--without-gmp' '--without-snmp' '--with-libxml-dir=/usr/local/opt/libxml2' '--with-pdo-odbc=unixODBC,/usr/local/opt/unixodbc' '--with-unixODBC=/usr/local/opt/unixodbc' '--with-bz2=/usr' '--with-openssl=/usr/local/opt/openssl' '--enable-fpm' '--with-fpm-user=_www' '--with-fpm-group=_www' '--with-curl' '--with-xsl=/usr' '--with-ldap' '--with-ldap-sasl=/usr' '--with-mysql-sock=/tmp/' '--with-mysqli=mysqlnd' '--with-mysql=mysqlnd' '--with-pdo-mysql=mysqlnd' '--disable-opcache' '--enable-pcntl' '--without-pear' '--enable-dtrace' '--disable-phpdbg' '--enable-zend-signals' Server API => Command Line Interface Virtual Directory Support => disabled Configuration File () Path => /usr/local/etc/php/5.5 Loaded Configuration File => /usr/local/etc/php/5.5/ Scan this dir for additional .ini files => /usr/local/etc/php/5.5/ ......
View function information
eric:~ youngeric$ php --rf date Function [ <internal:date> function date ] { - Parameters [2] { Parameter #0 [ <required> $format ] Parameter #1 [ <optional> $timestamp ] } }
View class information
eric:~ youngeric$ php --rc pdo Class [ <internal:PDO> class PDO ] { - Constants [89] { Constant [ integer PARAM_BOOL ] { 5 } Constant [ integer PARAM_NULL ] { 0 } Constant [ integer PARAM_INT ] { 1 } Constant [ integer PARAM_STR ] { 2 } Constant [ integer PARAM_LOB ] { 3 } Constant [ integer PARAM_STMT ] { 4 } Constant [ integer PARAM_INPUT_OUTPUT ] { 2147483648 } ......
Detect php code
eric:~ youngeric$ php -l PHP Parse error: syntax error, unexpected end of file, expecting ',' or ';' in on line 3 Errors parsing
As the best language in the world, PHP even has built-in server features (does it look shocking).
eric:Desktop youngeric$ php -S 127.0.0.1:8080 PHP 5.5.38 Development Server started at Thu Dec 22 09:44:20 2016 Listening on http://127.0.0.1:8080 Document root is /Users/youngeric/Desktop Press Ctrl-C to quit. [Thu Dec 22 09:44:29 2016] 127.0.0.1:52988 [404]: / - No such file or directory [Thu Dec 22 09:44:29 2016] 127.0.0.1:52989 [404]: / - No such file or directory
The above is all the content of this article. I hope it will be helpful to everyone's study and I hope everyone will support me more.