Analysis of working principles of apache and php
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:
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:
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. |

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

Session hijacking can be achieved through the following steps: 1. Obtain the session ID, 2. Use the session ID, 3. Keep the session active. The methods to prevent session hijacking in PHP include: 1. Use the session_regenerate_id() function to regenerate the session ID, 2. Store session data through the database, 3. Ensure that all session data is transmitted through HTTPS.

In PHP, exception handling is achieved through the try, catch, finally, and throw keywords. 1) The try block surrounds the code that may throw exceptions; 2) The catch block handles exceptions; 3) Finally block ensures that the code is always executed; 4) throw is used to manually throw exceptions. These mechanisms help improve the robustness and maintainability of your code.

In PHP, the difference between include, require, include_once, require_once is: 1) include generates a warning and continues to execute, 2) require generates a fatal error and stops execution, 3) include_once and require_once prevent repeated inclusions. The choice of these functions depends on the importance of the file and whether it is necessary to prevent duplicate inclusion. Rational use can improve the readability and maintainability of the code.

There are four main error types in PHP: 1.Notice: the slightest, will not interrupt the program, such as accessing undefined variables; 2. Warning: serious than Notice, will not terminate the program, such as containing no files; 3. FatalError: the most serious, will terminate the program, such as calling no function; 4. ParseError: syntax error, will prevent the program from being executed, such as forgetting to add the end tag.

PHP and Python each have their own advantages, and choose according to project requirements. 1.PHP is suitable for web development, especially for rapid development and maintenance of websites. 2. Python is suitable for data science, machine learning and artificial intelligence, with concise syntax and suitable for beginners.

HTTP request methods include GET, POST, PUT and DELETE, which are used to obtain, submit, update and delete resources respectively. 1. The GET method is used to obtain resources and is suitable for read operations. 2. The POST method is used to submit data and is often used to create new resources. 3. The PUT method is used to update resources and is suitable for complete updates. 4. The DELETE method is used to delete resources and is suitable for deletion operations.

PHP is a scripting language widely used on the server side, especially suitable for web development. 1.PHP can embed HTML, process HTTP requests and responses, and supports a variety of databases. 2.PHP is used to generate dynamic web content, process form data, access databases, etc., with strong community support and open source resources. 3. PHP is an interpreted language, and the execution process includes lexical analysis, grammatical analysis, compilation and execution. 4.PHP can be combined with MySQL for advanced applications such as user registration systems. 5. When debugging PHP, you can use functions such as error_reporting() and var_dump(). 6. Optimize PHP code to use caching mechanisms, optimize database queries and use built-in functions. 7
