samirz's avatar

No difference between PHP-FPM and Swoole in Production with nginx

Hello,

I installed swoole php extension at digitalocean droplet and used https://github.com/hhxsv5/laravel-s with laravel application, then i created a reverse proxy with nginx for the port that swoole server works on it.

My problem is that when i test the app with internal ip 127.0.0.1:8000 i notes that swoole works and the response time nearly to 15ms to 20ms but when i use the external ip i did't see any difference between FPM and swoole server, the response time nearly to 150 ms

This is my nginx config:

map $http_upgrade $connection_upgrade {
    default upgrade;
    ''      close;
}

server {
    root /var/www/beta/public;
    index index.html index.htm index.php index.nginx-debian.html;
    server_name beta.my-website.com;

    location = /index.php {
        # Ensure that there is no such file named "not_exists"
        # in your "public" directory.
        try_files /not_exists @swoole;
    }

    location / {
        try_files $uri $uri/ @swoole;
    }

    location @swoole {
        set $suffix "";

        if ($uri = /index.php) {
            set $suffix ?$query_string;
        }

        proxy_http_version 1.1;
        proxy_set_header Host $http_host;
        proxy_set_header Scheme $scheme;
        proxy_set_header SERVER_PORT $server_port;
        proxy_set_header REMOTE_ADDR $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection $connection_upgrade;

        # IF https
        # proxy_set_header HTTPS "on";

        proxy_pass http://127.0.0.1:8000$suffix;
    }

    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/beta.my-website.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/beta.my-website.com/privkey.pem;
    include /etc/letsencrypt/options-ssl-nginx.conf;
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;
}

server {
    if ($host = beta.my-website.com) {
        return 301 https://$host$request_uri;
    }

    server_name beta.my-website.com;
    listen 80;
    return 404;
}

any help to solve this problem?

0 likes
1 reply
itsmill3rtime's avatar

the purpose of these is more about concurrency, not latency. 15ms is pretty good execution time for laravel locally. and external will add latency as it has a longer path to travel. if you are using swoole it is to allow more simultaneous requests to be handled. you can go from tens or hundreds of requests per second on PHP-FPM, to thousands of requests per second on the same hardware using swoole or frankenphp. it looks like you are just misunderstanding the purpose of the framework

1 like

Please or to participate in this conversation.