Nginx
Nginx is a high-performance HTTP and reverse proxy server, also a IMAP/POP3/SMTP server.
To support the response of up to 5w concurrent connections, Nginx chooses epoll/kqueue as the network IO model.
Nginx can also be used as a Load balancer server, nginx written in C language.
Nginx is a master process and multiple worker processes, and the worker process is single-threaded. Each worker process can handle client requests in an asynchronous, non-blocking manner.
"Extended learning asynchronous non-blocking and Epoll Select poll Kqueue"
Nginx PHP is a fastcgi method to combine Nginx.
The client sends the request to the Nginx server, and the Nginx server passes the request to PHP for processing by fastcgi, and the result of the PHP processing is returned to the Nginx server via fastcgi.
The Nginx server then returns the result to the client.
FastCGI's knowledge
CGI is a general-purpose gateway interface that is the standard for interfaces between external applications and Web servers, and procedures for passing information between external applications and Web servers.
The CGI specification allows the Web server to execute external programs and send their output to a Web browser.
FastCGI is an improvement on CGI.
FastCGI is like a resident in-memory CGI, and when a request arrives, CGI will fork out a process to process the request.
However, FastCGI starts multiple CGI interpreters and waits for the Web server to connect when it starts loading.
When a client request arrives at webserver, the FASTCGI process Manager chooses a CGI interpreter to handle the request.
The advantage is that the CGI interpreter is loaded into memory and does not need to be read from memory every time, greatly improving the performance of the site
The problem with fastcgi is that it does not take effect immediately when modifying the PHP configuration. Need to reload a bit.
Blocking
A request from the client, the Web server receives the request, and the request requires IO operations.
The IO operation takes 10 seconds, and the Web server waits 10 seconds for 10 seconds for the Web server to reject other client requests.
Non-blocking
A client request comes in, the Web server receives the request, the request requires IO operation, and the IO takes 10 seconds
The Web server can still receive other client requests during the 10 seconds of the IO operation, and the Web server puts the file descriptors of those requests into a queue when the IO operation is ready.
The data is sent to this client.
Asynchronous non-blocking IO model
A master thread and multiple worker threads, a worker thread can handle multiple requests, and if the requested event is not handled properly, place the event file descriptor in a queue
When the event is processed, the result of the request return is read, so a large number of concurrent requests can be processed, but the concurrency here is only a request that is not processed because the worker is a thread
Therefore, the request can be processed at the same time only one.
It's just a constant switchover between requests, which is also because the asynchronous event is not ready and is actively yielding.
There is no price to switch here, and you can understand that the loop handles multiple prepared events, which is actually the case.
Compared with multithreading, this kind of event processing is a great advantage, do not need to create a thread, each request consumes less memory, no context switch,
Event handling is very lightweight. No more concurrent numbers will cause unnecessary waste of resources (context switching)
The above describes the Nginx learning and finishing, including the nginx aspects of the content, I hope that the PHP tutorial interested in a friend helpful.