How apache and php work

Source: Internet
Author: User
How apache and php work

This section describes how apache and php work.

Suppose 1000 people send requests to the php site at the same time, and these requests are sent to the apache server. how does the apache server work at this time? 1. create 1000 processes to process 1000 requests? 2. how many processes are created, and these processes contain many threads to process 1000 requests? 3. others? There is also fast-cgi, which is different from cgi and php-fpm. Use the preceding example to describe.

Additional reading:

  • FastCGI module (FastCGI) in Nginx
  • Knowledge about FastCGI in Nginx study notes
  • Php-fpm process management modes
  • Php-fpm configuration file details
  • Introduction to php-fpm configuration

You can use the above articles to learn the basic knowledge of fastcgi and php-fpm. Let's look at some concepts below: 1. CGI and FastCGI are two working modes of apache processing php scripts, as well as ISAPI, SAPI 2. php-fpm is not a working mode, but a process manager for PHP running in FastCGI mode. it is called PHP: fastCGI Process Manager3. how does one work? it depends on the working mode used when you set up the environment to Process php scripts. of course, there is also your apache configuration (number of connections, number of processes, number of threads, etc.), and the operating system used (different operating systems have different support for processes and threads, and different processing capabilities ). At the system level, different systems use different multi-processing modules (MPM) by default, as shown below:

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

You can use the apachectl-l command to view which MPM configuration is used by the current system. The main difference is that different systems use different configurations and have different levels of support for configuration items. The configuration items include: # 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: ctant number of worker threads in each server process # MaxRequestsPerChild: maximum number of reques Ts a server process serves. Then there is something at the apache level. let's take a look at the above description. you can configure the maximum number of connections, the number of threads in each process, and the number of requests processed by each process. Some of the operations depend on the value of your configuration. Then there is the php running mode. the mainstream running mode is FastCGI. of course, many previously configured servers use other modes, take a look at the specific command or view the apache configuration file. Below is a piece of content that I used to mark: 1. CGI (Common Gateway Interface/Common Gateway Interface) is generally an executable program, such as an EXE file, different from the WEB server, each occupies a different process. generally, a CGI program can only process one user request. In this way, when the number of user requests is very large, it will occupy a lot of system resources, such as memory, CPU time, etc., resulting in low efficiency. 2. ISAPI (Internet Server Application Program Interface) is a set of WEB service-oriented API interfaces provided by Microsoft. it can implement all the functions provided by CGI and is expanded on this basis, for example, filter application interfaces are provided. Most ISAPI applications are used as DLL dynamic libraries. they can be executed after being requested by users and will not disappear immediately after processing a user request, instead, it continues to reside in the memory and waits for other user input to be processed. In addition, the isapi dll application is in the same process as the WEB server, and the efficiency is significantly higher than that of CGI. 3. FastCGI is an open CGI extension of the Scalable Architecture. its main behavior is to keep the CGI interpreter process in the memory and thus achieve high performance. The repeated loading of the traditional CGI interpreter is the main cause of low CGI performance. if the CGI interpreter is kept in the memory and is scheduled by the FastCGI Process Manager, it can provide good performance and scalability. PHP is run in ISAPI mode. The biggest drawback of this method is poor stability. When PHP fails, the Apache process also dies. Advantages of running PHP in FastCGI mode: first, Apache will not be destroyed when PHP fails, only PHP processes are crashed (but FastCGI immediately restarts a new PHP process to replace the process ). Second, FastCGI runs PHP in better performance than ISAPI. finally, PHP5 and PHP4 can be run simultaneously at the integrated system level, apache configuration level, and PHP working mode level, 1000 requests do not need 1000 processes. it is likely that only two or fewer processes can be processed.

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.