Detailed analysis of PHP's 4 common operating methods

Source: Internet
Author: User
Tags bz2 fpm gettext http request openssl parse error php code zend

4 Common Ways to run PHP: CGI, FastCGI, Apache2handler, CLI.

1. CGI

CGI is the Universal Gateway Interface (Common Gatewag interface), it is a program, popular speaking CGI is like a bridge, the Web page and the Internet server to connect the Executive program, it will receive the HTML instructions to the server's execution program, Return the results of the server execution program to the HTML page. CGI has excellent cross-platform performance and can be implemented on almost any operating system.

The CGI method encounters a connection request (user request) to create a CGI subprocess, activates a CGI process, and then processes the request, finishes the subprocess, and ends the child process. This is the Fork-and-execute mode. So the CGI server has how many connection requests there will be the number of CGI child processes, the child process repeatedly loading is the main reason for the low performance of CGI. When the user requests a very large number of users will be heavily crowding out the system's resources such as memory, CPU time, etc., resulting in low performance.

2, FastCGI

FAST-CGI is an upgraded version of CGI, fastcgi is like a resident (long-live) CGI, which can be executed all the time, as long as it is activated, it will not take a while to fork once. PHP uses PHP-FPM (FastCGI process Manager), the full name of the PHP FastCGI process Manager for management.
Load the FASTCGI Process Manager (IIS ISAPI or Apache Module) when the WEB server is started. FastCGI the process manager itself, initiates multiple CGI interpreter processes (visible multiple php-cgi) 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 subprocess php-cgi.

The fastcgi process completes processing and returns standard output and error information from the same connection to the Web Server. When the fastcgi child process closes the connection, the request is processed. The fastcgi process then waits and processes the next connection from the FASTCGI process Manager (running in Web server). In the CGI mode, php-cgi quits here.

In the above scenario, you can imagine how slow CGI is usually. Each Web request PHP must reparse php.ini, reload all extensions, and reinitialize all data structures. With fastcgi, all of these occur only once when the process is started. An additional benefit is that persistent database connections (persistent DB connection) can work.

3, Apache2handler
PHP as the Apache module, the Apache server after the system is started, the advance generation of multiple copies of the process reside in memory, once the request appears, immediately use these free subprocess processing, so there is no delay in the generation of child processes. These server replicas do not exit immediately after processing an HTTP request, but stay on the computer for the next request. Faster response to client browser requests and higher performance.

4. CLI

CLI is the command-line run mode of PHP, the CLI side of the Run command is sometimes useful, the following summary several:

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

View extensions for current PHP

eric:~ youngeric$ php-m
[PHP Modules]
Bcmath
bz2
Calendar
Core
CType
Curl
Date
......

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

eric:~ youngeric$ Php-ini
Phpinfo ()
PHP Version => 5.5.38
System => Darwin eric.local 16.1.0 Darwin Kernel Version 16.1.0:wed Oct 20:31:56 PDT 2016; Root:xnu-3789.21.4~4/release_x86_64 x86_64
Builddate=> 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/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 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 Interface
Virtual Directory Support => disabled
Configuration File (php.ini) Path =>/usr/local/etc/php/5.5
Loaded Configuration File =>/usr/local/etc/php/5.5/php.ini
Scan this dirforadditional. ini files =>/usr/local/etc/php/5.5/conf.d
......

View function Information

eric:~ youngeric$ PHP--rfdate
Function [<internal:date>functiondate] {
-Parameters [2] {
Parameter #0 [<required> $format]
Parameter #1 [<optional> $timestamp]
}
}

View class Information

eric:~ youngeric$ PHP--RC PDO
Class [<internal:pdo>classpdo] {
-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}
......

Detecting PHP Code

eric:~ youngeric$ php-l jiance.php
PHP Parse error:syntax Error, unexpectedendof file, expecting ', ' or '; In jiance.php on line 3
Errors parsing jiance.php

As the world's best language, PHP even has built-in server functionality (there is no shock to look at it).

eric:desktop youngeric$ Php-s 127.0.0.1:8080
 
PHP 5.5.38 Development Server started at Thu Dec 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 09:44:29 2016] 127.0.0.1:52988 [404]:/-No such fileordirectory
[Thu Dec 09:44:29 2016] 127.0.0.1:52989 [404]:/favicon.ico-no such file

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.