Analysis of working principles of apache and php

WBOY
Release: 2016-07-25 09:12:19
Original
2674 people have browsed it

Introducing the working principles of apache and php.

Suppose there are 1,000 people requesting the php site at the same time, and these requests are passed to the apache server. How does the apache server work at this time? 1. Create 1000 processes to handle 1000 requests? 2. Create many processes, and these processes contain many threads to handle 1,000 requests? 3. Others? There is also fast-cgi, which is different from cgi and php-fpm. Use the above example to illustrate.

Extended reading:

  • Detailed explanation of FastCGI module (FastCGI) in Nginx
  • Nginx study notes: knowledge about FastCGI
  • Detailed explanation of the two process management modes of php-fpm
  • Detailed explanation of php-fpm configuration file
  • Introduction to the configuration of php-fpm

You can learn about the basic knowledge of fastcgi and php-fpm through the above articles. Let’s look at some concepts: 1. CGI and FastCGI are two working modes for apache to process php scripts, as well as ISAPI, SAPI, etc. 2. php-fpm is not a working mode, but a process manager for PHP running in FastCGI mode. Its full name is PHP: FastCGI Process Manager. 3. How it works depends on which working mode you use to process php scripts when setting up the environment. Of course, your apache configuration (number of connections, number of processes, number of threads, etc.) is also indispensable, and what is used operating system (different operating systems have different support for processes and threads, and different processing capabilities). Let’s talk about the system level first. Different systems use different multi-processing modules (MPM) by default, as follows:

  1. BeOS beos
  2. Netware mpm_netware
  3. OS/2 mpmt_os2
  4. Unix prefork
  5. Windows mpm_winnt
Copy code

You can use the apachectl -l command to view the current system usage Which MPM configuration. The main difference is that different systems use different configurations and have different levels of support for configuration items. Generally include the following configuration items: # StartServers: initial number of server processes to start # MaxClients: maximum number of simultaneous client connecti # MinSpareThreads: minimum number of worker threads which are kept spare # MaxSpareThreads: maximum number of worker threads which are kept spare # ThreadsPerChild: count number of worker threads in each server process # MaxRequestsPerChild: maximum number of requests a server process serves etc. Then there are things at the apache level, Looking at the above description, the maximum number of connections, how many threads each process has, how many requests each process handles, etc. can all be configured. How you handle some of these depends on your configuration values. Then there is the level of PHP running mode. The current mainstream operating mode is FastCGI. Of course, many previously configured servers will use other modes. You can know the details by using the command or looking at the apache configuration file. Let me just post a piece of content that I marked before: 1. CGI (Common Gateway Interface) is generally an executable program, such as an EXE file, and the WEB server each occupies a different process, and generally a CGI program can only handle one user request. In this way, when the number of user requests is very large, it will occupy a large amount of system resources, such as memory, CPU time, etc., resulting in low performance. 2. ISAPI (Internet Server Application Program Interface) is a set of API interfaces for WEB services provided by Microsoft. It can realize all the functions provided by CGI and expand on this basis, such as providing a filter application program interface. ISAPI applications are mostly used in the form of DLL dynamic libraries, which can be executed after being requested by the user. They will not disappear immediately after processing a user request, but will continue to reside in the memory and wait for other user inputs to be processed. In addition, the ISAPI DLL application and the WEB server are in the same process, and the efficiency is significantly higher than that of CGI. 3. FastCGI is an open extension of CGI with a scalable architecture. Its main behavior is to keep the CGI interpreter process in memory and thus obtain higher performance. Repeated loading of traditional CGI interpreters is the main reason for low CGI performance. If the CGI interpreter remains in memory and accepts FastCGI process manager scheduling, it can provide good performance, scalability, etc. The biggest disadvantage of running PHP in ISAPI mode is its poor stability. When PHP goes wrong, the Apache process will also die. Advantages of running PHP in FastCGI mode: The first is that when PHP goes wrong, it will not bring down Apache, but PHP's own process will crash (but FastCGI will immediately restart a new PHP process to replace the crashed process). Secondly, FastCGI mode has better performance than ISAPI mode when running PHP. Finally, you can run PHP5 and PHP4 at the same time At the comprehensive system level, Apache configuration level, and PHP working mode level, 1,000 requests definitely do not require 1,000 processes. It is likely that only two digits or even fewer processes can be processed.



Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template