Explanation of four common php running methods and php4

Source: Internet
Author: User
Tags ldap parse error

Explanation of four common php running methods and php4

Four Common php running modes: CGI, FastCGI, APACHE2HANDLER, and CLI.

1. CGI

CGI is the common gatewag interface. It is a program. Generally speaking, CGI is like a bridge, which connects the webpage to the execution program on the WEB server, it passes the commands received by HTML to the execution program on the server, and then returns the results of the execution program on the server to the HTML page. CGI provides excellent cross-platform performance and can be implemented on almost any operating system.

In CGI Mode, a connection request (user request) must first create a cgi sub-process, activate a CGI process, process the request, and end the sub-process after processing. This is the fork-and-execute mode. As a result, the number of connection requests to servers in the cgi Mode is limited to the number of cgi sub-processes. repeated loading of sub-processes is the main cause of low cgi performance. When the number of user requests is very large, a large amount of system resources such as internal storage and CPU time will be squeezed out, 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, it does not take time to fork once every time. PHP uses PHP-FPM (FastCGI Process Manager), the full name of PHP FastCGI Process Manager for management.
When the Web Server starts, load the FastCGI Process Manager (iis isapi or Apache Module ). FastCGI Process Manager initializes itself, starts Multiple CGI interpreter processes (multiple php-cgi are visible), 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. The Web server sends CGI Environment Variables and standard input to the FastCGI sub-process php-cgi.

After the FastCGI sub-process completes processing, the standard output and error messages are returned from the same connection to the Web Server. When the FastCGI sub-process closes the connection, the request processing is complete. The FastCGI sub-process then waits for and processes the next connection from the FastCGI Process Manager (running on the Web Server. In CGI Mode, php-cgi exits here.

In the above cases, you can imagine how slow CGI is. For each Web request, PHP must re-Parse php. ini, re-load all extensions, and initialize all data structures. With FastCGI, all of these occur only once when the process starts. An additional benefit is that Persistent database connection can work.

3. APACHE2HANDLER
PHP is used as the Apache module. After the Apache server is started, multiple process replicas are generated in advance and reside in the memory. Once you find them, use these idle sub-processes for processing, in this way, there is no latency caused by the generation of sub-processes. These server copies do not exit immediately after processing an HTTP request, but are stuck in the computer waiting for the next request. The response to client browser requests is faster and the performance is high.

4. CLI

Cli is the command line running mode of php, and cli-Side Running commands are sometimes useful. The following is a summary:

View php version information

eric:~ youngeric$ php -vPHP 5.5.38 (cli) (built: Oct 1 2016 23:03:00) Copyright (c) 1997-2015 The PHP GroupZend Engine v2.5.0, Copyright (c) 1998-2015 Zend Technologies

View current php extensions

eric:~ youngeric$ php -m[PHP Modules]bcmathbz2calendarCorectypecurldate......

View php. ini configuration information (equivalent to using the phpinfo () function)

eric:~ youngeric$ php -iniphpinfo()PHP Version => 5.5.38System => Darwin eric.local 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_64Build Date => Oct 1 2016 23:01:51Configure 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/conf.d' '--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/mysql.sock' '--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 InterfaceVirtual Directory Support => disabledConfiguration File (php.ini) Path => /usr/local/etc/php/5.5Loaded Configuration File => /usr/local/etc/php/5.5/php.iniScan this dir for additional .ini files => /usr/local/etc/php/5.5/conf.d......

View function Information

eric:~ youngeric$ php --rf dateFunction [ <internal:date> function date ] { - Parameters [2] {  Parameter #0 [ <required> $format ]  Parameter #1 [ <optional> $timestamp ] }}

View class information

eric:~ youngeric$ php --rc pdoClass [ <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 jiance.phpPHP Parse error: syntax error, unexpected end of file, expecting ',' or ';' in jiance.php on line 3Errors parsing jiance.php

As the best language in the world, php even has built-in server functions (not surprising ).

eric:Desktop youngeric$ php -S 127.0.0.1:8080PHP 5.5.38 Development Server started at Thu Dec 22 09:44:20 2016Listening on http://127.0.0.1:8080Document root is /Users/youngeric/DesktopPress 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]: /favicon.ico - No such file or directory

The above is all the content of this article. I hope it will be helpful for your learning and support for helping customers.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.