Home > PHP Framework > Swoole > body text

How to mix nginx and swoole

(*-*)浩
Release: 2019-12-14 14:06:30
Original
2563 people have browsed it

How to mix nginx and swoole

Nginx based on epoll

With epoll, one process can theoretically have an unlimited number of connections without polling, which is truly Solved the problem of c10k. (Recommended learning: swoole video tutorial)

Nginx is an asynchronous non-blocking server program based on epoll. Naturally, it is understandable that Nginx can easily handle millions of concurrent connections.

How swoole handles high concurrency

①Reactor model introduction

IO multiplexing asynchronous non-blocking programs use the classic Reactor model. Reactor, as the name suggests, is a reactor. Meaning, it does not handle any data sending and receiving itself. It can only monitor the event changes of a socket (can also be a pipe, eventfd, signal) handle.

Note: What is a handle? The English word handle is handler, which can be vividly compared to the handle of a pot or a spoon. That is, the unique identifier of the resource and the ID of the resource. Resources can be operated through this ID.

Reactor is just an event generator. The actual operations on the socket handle, such as connect/accept, send/recv, and close, are completed in the callback.

Because reactor is based on epoll, each reactor can handle countless connection requests. In this way, swoole can easily handle high concurrency.

nginx configuration:

server {
    listen  80;
    server_name  www.swoole.com;
    root  /data/wwwroot/www.swoole.com;
    location / {
        if (!-e $request_filename){
            proxy_pass http://127.0.0.1:9501;
        }
    }
}
Copy after login

9501 is the address that the swoole server listens to. root is set to the directory of static files. When requesting a static file, it is processed directly by Nginx. When the requested file does not exist, it is sent to the Swoole server for processing.

The above is the detailed content of How to mix nginx and swoole. For more information, please follow other related articles on the PHP Chinese website!

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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!