search
HomePHP FrameworkSwooleHow to mix nginx and swoole

How to mix nginx and swoole

Dec 14, 2019 pm 02:06 PM
swoole

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;
        }
    }
}

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!

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

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

Hot Tools

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.