Home  >  Article  >  Backend Development  >  What are the operating environments for php?

What are the operating environments for php?

王林
王林Original
2019-10-10 17:51:544046browse

What are the operating environments for php?

1. nginx swoole

swoole is an asynchronous, parallel, high-performance network communication engine written in pure C language and provides Asynchronous multi-threaded server in PHP language. Swoole has built-in http/websocket server and client, http2.0 server, supports coroutines similar to Go language, and can use synchronous code to implement one-step procedures.

swoole adopts the Reactor model of I/O multiplexing and asynchronous blocking, and uses multi-threaded Reactor and multi-threaded Worker to implement asynchronous I/O. Reactor is based on Epoll, and each Reactor can handle countless connection requests, so it can easily handle high concurrency.

In Nginx swoole mode, nginx serves as the front-end access layer forwarder and swoole serves as the application server to build high-concurrency web services.

2. nginx php-fpm

FastCGI is a neutral technical standard, and php-fpm is the FastCGI process manager for the PHP language.

CGI's fork-and-execute mode has many shortcomings. Every time a request is received, a process must be forked for processing, and only one request can be received to make a response; PHP must re-parse php for every web request. ini file, reload all extensions and initialize all data structures.

FastCGI will be started in advance, parsing the php.ini file, loading extensions, and initializing the data structure will only be completed at startup. It exists as a CGI management server and uses a process/thread pool to pre-start a series of The child process is waiting for processing. Then the web server sends a request. Once FastCGI receives the request, it is handed over to the child process for processing. There is no need to start CGI after receiving the request, which will be much faster. The web server requests the FastCGI process manager through a socket long connection.

The FastCGI process is like a resident CGI. When a request arrives, the FastCGI process manager selects and connects a PHP-CGI interpreter to receive the environment variables and standard input sent by the web server. After the request processing is completed Returns standard output or error to the web server from the same connection as the PHP-CGI interpreter subprocess waiting to handle the next connection from the FastCGI process manager.

3. apache mod_php

Running php in mod_php mode means that php is started as a module of apache. Only when apache starts, the php.ini configuration file will be read and the extension module will be loaded. Extension modules will not be read and loaded while apache is running. For stability and security reasons, Apache usually uses the default prefork mode to run PHP programs. In prefork mode, a separate control process is responsible for spawning child processes, which are used to listen for requests and respond.

Apache always tries to keep some spare or idle child processes for upcoming requests, so that the client does not need to wait for the child process to be generated before getting the service. However, once the number of connections increases, Apache must generate more processes to respond to requests. The CPU switches processes frequently, which consumes events and resources, causing Apache performance to decrease; at the same time, Apache is synchronously blocking the I/O model. Under this situation, select traverses multiple connection handles to know whether the handle has event notification, so the efficiency is very low.

Recommended tutorial: PHP video tutorial

The above is the detailed content of What are the operating environments for php?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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