我目前正在使用nginx和PHP FastCGI,但这种安排受到限制,它一次只能服务一个HTTP请求。(参见这里)。我从Windows命令提示符启动PHP,执行;
c:'Program Files'PHP>php-cgi -b 127.0.0.1:9000
然而,有另一种方式来运行PHP称为"快速CGI进程管理器"(PHP- fpm)。
当运行在Windows 7背后的nginx, PHP-FPM可以处理多个同时HTTP请求?
我最终得到了这个解决方案:您只需启动几个php-cgi进程并将它们绑定到不同的端口,并且您需要更新nginx配置:
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;
}
}
为了方便,我创建了简单的批处理文件。
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 ..
和stop_sandbox.bat
:
pstools'pskill php-cgi
pstools'pskill mysqld
pstools'pskill nginx
如你所见,有2个依赖项:pstools和runhiddenconsole.exe
有一个更好的选择。
在nginx配置中使用简单的快速cgi设置
nginx.conf
server {
....
location ~ '.php$ {
try_files $uri =404;
include fastcgi.conf;
fastcgi_pass 127.0.0.1:9001;
fastcgi_read_timeout 60;
allow 127.0.0.1;
allow ::1;
deny all;
}
}
然后在start.bat文件
set PATH=%cd%'bin'php;%PATH%
set PHP_FCGI_MAX_REQUESTS=0
set PHP_FCGI_CHILDREN=10
RunHiddenConsole.exe %cd%/php/php-cgi.exe -b 127.0.0.1:9001 -c %cd%/php/php.ini
PHP_FCGI_CHILDREN变量是魔术发生的地方。PHP_FCGI_MAX_REQUESTS也很重要