Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can Windows PHP-FPM serve multiple simultaneous requests?

I'm currently using nginx and PHP FastCGI but that arrangement suffers from the limitation that it can only serve one HTTP request at a time. (See here.) I start PHP from the Windows command prompt by doing;

c:\Program Files\PHP>php-cgi -b 127.0.0.1:9000

However there is another way to run PHP know as "Fast CGI Process Manager" (PHP-FPM).

When running on Windows 7 behind nginx, can PHP-FPM handle multiple simultaneous HTTP requests?

like image 565
Nigel Alderton Avatar asked Dec 21 '22 07:12

Nigel Alderton


1 Answers

I ended up with this solution: you simply start several php-cgi processes and bind them to different ports, and you need to update nginx config:

http {

    upstream php_farm {
        server 127.0.0.1:9000 weight=1;
        server 127.0.0.1:9001 weight=1;
        server 127.0.0.1:9002 weight=1;
        server 127.0.0.1:9003 weight=1;
    }

    ...

    server {
      ...
      fastcgi_pass   php_farm;
    }

}

For the sake of convenience, I created simple batch files.

start_sandbox.bat:

@ECHO OFF
ECHO Starting sandbox...

RunHiddenConsole.exe php\php-cgi.exe -b 127.0.0.1:9000 -c php\php.ini
RunHiddenConsole.exe php\php-cgi.exe -b 127.0.0.1:9001 -c php\php.ini
RunHiddenConsole.exe php\php-cgi.exe -b 127.0.0.1:9002 -c php\php.ini
RunHiddenConsole.exe php\php-cgi.exe -b 127.0.0.1:9003 -c php\php.ini

RunHiddenConsole.exe mysql\bin\mysqld --defaults-file=mysql\bin\my.ini --standalone --console

cd nginx && START /B nginx.exe && cd ..

and stop_sandbox.bat:

pstools\pskill php-cgi

pstools\pskill mysqld

pstools\pskill nginx

as you can see, there are 2 dependencies: pstools and runhiddenconsole.exe

like image 107
Slava Popov Avatar answered Dec 22 '22 19:12

Slava Popov