Windows Nginx FastCGI PHP 并发阻塞问题
问题描述:
在windows上开发项目,使用hosts解析域名 如下:
127.0.0.1 www.a.com 127.0.0.1 www.b.com
配置好nginx php,配置如下:
www.a.com项目 配置如下
server { listen 80; server_name www.a.com; #access_log logs/host.access.log main; root /PDT/data/html/a; location ~ \.php$ { fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param PATH_INFO $fastcgi_path_info; include fastcgi_params; } }
index.php代码如下:
<?php $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, 'http://www.b.com/index.php'); curl_setopt($ch, CURLOPT_HEADER, false); curl_setopt($ch, CURLINFO_HEADER_OUT, true); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_AUTOREFERER, true); $data = curl_exec($ch); curl_close($ch); echo $data;
www.b.com 项目配置如下:
server { listen 80; server_name www.b.com; #access_log logs/host.access.log main; root /PDT/data/html/b; location ~ \.php$ { fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param PATH_INFO $fastcgi_path_info; include fastcgi_params; } }
index.php 代码如下:
<?php echo "www.b.com";
浏览器访问 www.b.com/index.php www.a.com/index.php
问题分析:
windows下的nginx也支持这种fastcgi配置,但是‘PHP_FCGI_CHILDREN’ 这个环境变量只在Linux下有效,windows下不会产生fastcgi的子进程(windows下好像只能产生线程,热fastcgi需要产生进程,我也不懂。。),导致windows下其实并不支持nginx这种多并发。
windows 下没有PHP-FPM,windows下Nginx的配置都是fastcgi_pass 127.0.0.1:9000; 也就是说cgi根本不会自动产生新进程去处理并发请求,只能排队等待.
解决方案:
发表评论
要发表评论,您必须先登录。