【发布时间】:2018-07-25 08:27:21
【问题描述】:
我有一个运行 NGINX 和 PHP 的网络服务器,带有一个非常基本的多客户端测试。
<?php
if(isset($_GET['query'])) {
echo "HELLO MY NAME IS WEBSERVER";
}
if(isset($_GET['sleep'])) {
sleep(10);
}
?>
如果我运行http://servername.com/index.php?query,我会立即得到响应。
如果我同时运行 ?sleep 然后 ?query,则 ?query 似乎已排队等待 ?sleep 完成。
这发生在多个客户端上。 Client A 可以请求?sleep,这会影响Client B 的?query 请求。客户端 B 是完全不同的机器。
是否有任何方法可以调整 php.ini 或我的 nginx 配置以允许生成单独的 php 工作进程(或类似的东西?)
编辑:对于一点背景,这是我的配置。
nginx.conf:
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9123;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
fastgci_params:
fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_param REQUEST_URI $request_uri;
fastcgi_param DOCUMENT_URI $document_uri;
fastcgi_param DOCUMENT_ROOT $document_root;
fastcgi_param SERVER_PROTOCOL $server_protocol;
fastcgi_param REQUEST_SCHEME $scheme;
fastcgi_param HTTPS $https if_not_empty;
fastcgi_param GATEWAY_INTERFACE CGI/1.1;
fastcgi_param SERVER_SOFTWARE nginx/$nginx_version;
fastcgi_param REMOTE_ADDR $remote_addr;
fastcgi_param REMOTE_PORT $remote_port;
fastcgi_param SERVER_ADDR $server_addr;
fastcgi_param SERVER_PORT $server_port;
fastcgi_param SERVER_NAME $server_name;
# PHP only, required if PHP was built with --enable-force-cgi-redirect
fastcgi_param REDIRECT_STATUS 200;
php执行(runphp.bat):
set PATH=%cd%\php;%PATH%
start %cd%\php\php-cgi.exe -b 127.0.0.1:9123
编辑 2: 好的,看来我需要 PHP-FPM,这在 Windows 上不可用:
It is important to note that FPM is not built with the windows binaries. Many of the guides you may find online rely on php-cgi.exe. Unfortunately they call it FPM but this is incorrect!
The executable php-cgi.exe that is bundled with the windows binaries is a FastCGI interface but it is *not* FPM (Fastcgi Process Manager). php-cgi.exe does not have multi-threading or concurrent request support, nor support for any of the FPM configuration options.
因此,作为一种解决方法,我正在尝试使用多个 php 服务器/进程的方法:
upstream php {
server 127.0.0.1:9000;
server 127.0.0.1:9001;
server 127.0.0.1:9002;
server 127.0.0.1:9003;
}
location ~ \.php$ {
fastcgi_pass php;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
但是,NGINX 在这种配置下根本不会启动。它似乎不想接受任何“上游 php {}”
有什么想法吗?
谢谢
【问题讨论】:
-
PHP到底是如何集成到nginx中的? PHP-FPM?配置了多少个 FPM 工作者?
-
php-fpm的服务器有多少核?创建了多少php-fpm子进程?您不应该遇到这种行为,我无法在我的设置中复制它。