CGI ISAP SAPI, etc.

Source: Internet
Author: User
Tags php error sapi

1. CGI and fastcgi are two of Apache's working modes for PHP scripting, as well as ISAPI,SAPI.

2, and PHP-FPM is not a work mode, but a PHP in FastCGI mode running Process Manager, all called php:fastcgi process Manager

3, how to work is to see when you set up the environment to use which mode of work to deal with PHP scripts, of course, but also your Apache configuration (number of connections, number of processes, number of threads, etc.), there is the operating system used (different operating systems for process and thread support different, processing power is different).

First of all, the system level, different systems by default will use a different multi-processing module (MPM), as follows:

BeOS beos
Netware mpm_netware
Os/2 mpmt_os2
Unix prefork
Windows mpm_winnt

You can use the APACHECTL-L command to see which MPM configuration is used by the current system.

The main difference is that different systems use different configurations, and the level of support for configuration items is different.

These configuration items typically include the following:

# startservers:initial number of server processes to start
# maxclients:maximum number of simultaneous client connections
# minsparethreads:minimum number of worker threads which is kept spare
# maxsparethreads:maximum number of worker threads which is kept spare
# threadsperchild:constant number of worker threads in each server process
# maxrequestsperchild:maximum number of requests a server process serves

Wait a minute......

And then it's Apache-level stuff,

Look at the instructions above, what is the maximum number of connections, how many threads each process has, and how many requests each process handles, all of which can be configured. How to handle some of these depends on the value of your configuration.

And then there's the level of PHP run mode,

Now the main mode of operation is fastcgi, of course, there are many previously configured servers will use other modes, specific commands to look at or look at the Apache configuration file to know. Here's a straight piece of what I used to mark down:

    1, CGI (Universal Gateway Interface/common Gateway Interface) are generally executable programs, such as EXE files, and Web servers each occupy a different process, and generally a CGI program can only handle one user request. In this way, when the user requests a very large amount of resources, such as memory, CPU time, and so on, resulting in low performance.     2, ISAPI (Internet Server application program Interface) is a set of Web service-oriented API interface provided by Microsoft, it can realize all the functions provided by CGI, and extend it on this basis. , such as providing a filter application interface. Most ISAPI applications are used in the form of DLL dynamic libraries, can be executed after a user request, do not disappear immediately after processing a user request, but continue to reside in memory waiting to be processed by other user input. In addition, ISAPI DLL applications and Web servers are in the same process and are significantly more efficient than CGI.     3, fastcgi is a CGI open extension of the scalable architecture, whose main behavior is to keep the CGI interpreter process in memory and thus achieve high performance. The traditional CGI interpreter's repeated loading is the main reason for the poor CGI performance, if the CGI interpreter remains in memory and accepts the FASTCGI process manager scheduling, it can provide good performance, scalability, and so on.   Run PHP in ISAPI mode, the biggest drawback is that the stability is not good, when PHP error, the Apache process also died.  FASTCGI the advantages of running PHP: The first is that PHP error will not bring down Apache, but PHP's own process when it fell (but FastCGI will immediately restart a new PHP process to replace the lost process). Next FastCGI mode to run PHP better than ISAPI mode performance Finally, can be run at the same time PHP5 and php4  comprehensive system level, Apache configuration level, PHP working mode level, 1000 requests are absolutely no 1000 processes, It is likely that only two-bit or fewer processes can be processed. Let's start by introducing why we want to connect Apache with Tomcat. In fact, Tomcat itself has provided the HTTP service, the default port of the service is 8080, after the installation of Tomcat through the 8080 port can be directly used by Tomcat running applications, you can also change the port to 80.
Now that Tomcat itself can provide such a service, why should we introduce Apache or some other specialized HTTP server? There are several reasons:
1. Improve the processing performance of static files
2. Using a WEB server for load balancing and fault tolerance
3. Seamless upgrade of applications
This three point for a Web site is very important, we hope that our site is not only fast, but also stable, not because of a Tomcat outage or upgrade program caused the user can not access, and to complete these features of the best HTTP server is only Apache HTTP Server, it is the most closely and reliably combined with Tomcat.
Next we introduce three ways to integrate Apache and Tomcat together.

JK
This is the most common way, you can find many Web pages on the Internet to configure JK, of course, the most complete is the official documentation. JK itself has two versions are 1 and 2, the current 1 latest version is 1.2.19, and version 2 has been obsolete, and no longer have a new version of the launch, it is recommended that you use version 1.
JK is communicating with the Tomcat server via the AJP protocol, and the tomcat default AJP Connector port is 8009. JK itself provides a monitoring and management page Jkstatus, through which jkstatus can monitor JK's current working status and set the connection to Tomcat, as shown in:
Figure 1: Monitoring and managing the page Jkstatus
In this figure we can see the current JK with two connections to 8109 and 8209 ports, the current S2 This connection is a stop state, and S1 this connection since the last restart has processed more than 470,000 requests, traffic reached 6.2 G, the largest number of concurrency 13 and so on. We can also use the Jkstatus management function to switch JK to different Tomcat, such as the S2 enabled, and deactivate S1, which is very useful when updating the application, and the entire switching process for the user is transparent, also achieved a seamless upgrade. About JK configuration articles online has been very much, here we no longer detailed introduction of the entire configuration process, but I want to talk about the configuration of the idea, as long as the configuration of the idea, JK is a very flexible component.
JK's configuration is the most critical of three files, respectively
httpd.conf
Apache server configuration file for loading JK modules and specifying JK profile information
workers.properties
Connection definition file to the TOMCAT server
uriworkermap.properties
URI mapping file, which specifies which URLs are handled by TOMCAT, you can also configure these URIs directly in httpd.conf, but the advantage of being independent of these configurations is that the JK module periodically updates the contents of the file so that we do not need to restart the Apache server when we modify the configuration.
Where the second to third profile name can be customized. The following is a typical httpd.conf to JK configuration
# (HTTPD.CONF)
# load MOD_JK Module
LoadModule Jk_module modules/mod_jk.so
#
# Configure MOD_JK
#
Jkworkersfile conf/workers.properties
Jkmountfile conf/uriworkermap.properties
Jklogfile Logs/mod_jk.log
Jkloglevel warn
Next we create a new two files in Apache's conf directory, namely Workers.properties, Uriworkermap.properties. The contents of these two files are probably as follows
#
# workers.properties
#
#  List the workers by name
Worker.list=dlog4j, status
# localhost  Server 1
# ------------------------
worker.s1.port=8109
Worker.s1.host=localhost
WORKER.S1.TYPE=AJP13
# localhost server 2
# ------------------------
worker.s2.port=8209
Worker.s2.host=localhost
worker.s2.type=ajp13
worker.s2.stopped=1
Worker. DLOG4J.TYPE=LB
worker.retries=3
Worker. DLOG4J.BALANCED_WORKERS=S1, S2
Worker. Dlog4j.sticky_session=1
Worker.status.type=status
The above workers.properties configuration is the one we used for the screen capture page in front of us. First we configured two workers of type ajp13 to be S1 and S2, which point to the same server running on two different ports 8109 and 8209 Tomcat. Next we configured a worker of type lb (that is, the meaning of load balancing), whose name is dlog4j, a logical worker that manages the two physical connections S1 and S2 that were previously configured. Finally, a worker of the type status is configured, which is the module used to monitor the JK itself. With these three workers is not enough, we also need to tell JK, which workers are available, so there is worker.list = dlog4j, statusThis line is configured.
Next is the URI mapping configuration, we need to specify which links are handled by Tomcat, and which are processed directly by Apache, see the following file you can understand the meaning of the configuration
/*=dlog4j
/jkstatus=status
!/*.gif=dlog4j
!/*.jpg=dlog4j
!/*.png=dlog4j
!/*.css=dlog4j
!/*.js=dlog4j
!/*.htm=dlog4j
!/*.html=dlog4j
I'm sure you understand. More than half: All requests are handled by the dlog4j worker, but with a few exceptions, the/jkstatus request is handled by the status worker. What does the exclamation mark in front of each row of data in this configuration mean? The exclamation point indicates that the next URI should not be processed by JK, that is, Apache directly handles all images, CSS files, JS files, and static HTML text files.
Through the configuration of Workers.properties and uriworkermap.properties, there can be a variety of combinations to meet the requirements of a Web site we have previously proposed. You might as well try it!


Http_proxy
This is the use of Apache's own mod_proxy module to connect Tomcat using proxy technology. Make sure you are using the 2.2.x version of the Apache server before you configure it. Because the 2.2.x version of this module has been rewritten, greatly enhanced its functionality and stability.
Http_proxy mode is a proxy based on the HTTP protocol, so it requires Tomcat to provide HTTP services, which means that Tomcat's HTTP Connector must be enabled. One of the simplest configurations is as follows

Proxypass/images!
Proxypass/css!
Proxypass/js!
proxypass/http://localhost:8080/
In this configuration, we proxy all http://localhost requests to http://localhost:8080/, which is the access address of Tomcat, except for images, CSS, JS and several other directories. We can also use Mod_proxy to do load balancing, and then look at the following configuration
Proxypass/images!
Proxypass/css!
Proxypass/js!
proxypass/balancer://example/
<proxy balancer://example/>
Balancermember http://server1:8080/
Balancermember http://server2:8080/
Balancermember http://server3:8080/
</Proxy>
The configuration is much simpler than JK, and it can also be used to monitor the status of the cluster running through a single page, and make some simple maintenance settings.
Figure 2: Monitor cluster run status


Ajp_proxy
Ajp_proxy connection is in fact the same way as http_proxy, are provided by the Mod_proxy function. The same is true for configuration, just replace http://To ajp://, and the port where Tomcat AJP Connector is connected. The configuration of the above example can be changed to:

Proxypass/images!
Proxypass/css!
Proxypass/js!
proxypass/balancer://example/
<proxy balancer://example/>
Balancermember ajp://server1:8080/
Balancermember ajp://server2:8080/
Balancermember ajp://server3:8080/
</Proxy>
Using proxy connection, you need to load the required modules on Apache, mod_proxy related modules are mod_proxy.so, mod_proxy_connect.so, mod_proxy_http.so, Mod_proxy_ Ftp.so, mod_proxy_ajp.so, of which mod_proxy_ajp.so only in Apache 2.2.x. If you are using Http_proxy, you will need to load mod_proxy.so and mod_proxy_http.so, and if it is ajp_proxy you will need to load the two modules mod_proxy.so and mod_proxy_ajp.so.


Comparison of the three
Relative to the JK connection, the latter two are relatively simple in configuration, flexibility is not inferior. But in terms of stability is not like JK such a proven, after all, Apache 2.2.3 launch of the time is not long, the use of this connection method of the site is not many, so if it is applied to the key Internet site, it is recommended to use JK connection method.

CGI ISAP SAPI, etc.

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.