window+nginx+php-cgi的php-cgi线程/子进程问题

见bbs

http://bbs.csdn.net/topics/390803643/close


正常的配置情况下,window的php-cgi是不会出现多线程/子进程的,例如以下配置


fastcgi_pass   127.0.0.1:9000;


这时也就意味着当二个php文件同一时候请求解析时,就会出现堵塞处理,处理时间就会是a.php+b.php,而不是并行,是串行时间了.


如a.php

sleep(100);echo 1;

b.php

echo 2;

先执行a.php,100秒后输出1.在执行a.php的同一时候,执行b.php,2却出如今100秒以后.如果...却不是一执行就立马出现,由于上面的配置受影响导致解析是串行时间了.





在google.翻了几个小时.

找到

The problem is that the PHP_FCGI_CHILDREN environment variable is ignored under windows, therefore php-cgi does not spawn children, and when PHP_FCGI_MAX_REQUESTS is reached the process terminates.


Check on PHP's source, file cgi_main.c, around line 1982:


#ifndef PHP_WIN32
  /* Pre-fork, if required */
  if (getenv("PHP_FCGI_CHILDREN")) {
    char * children_str = getenv("PHP_FCGI_CHILDREN");
...


So, php with fast-cgi will **never** work on Windows.


The question is, why is forking disabled under windows?




-------------https://bugs.php.net/bug.php?

id=49859-----------


得知window不支持??

???


看到网上有非常多人不懂怎么处理.而我的是測试server,认为就算了.灵机一动.就手工的开起几个php-cgi等着吧.

于是变通方案时.


手工开起n个php-cgi等着




::window不支持 nginx的多线程,仅仅能手工生成多个php-cgi
start "fcgi服务" /MIN  /D "%batDir%php"  php-cgi.exe -b 127.0.0.1:9000 -c "%batDir%php/php.ini"
start "fcgi服务" /MIN  /D "%batDir%php"  php-cgi.exe -b 127.0.0.1:9001 -c "%batDir%php/php.ini"
start "fcgi服务" /MIN  /D "%batDir%php"  php-cgi.exe -b 127.0.0.1:9002 -c "%batDir%php/php.ini"
start "fcgi服务" /MIN  /D "%batDir%php"  php-cgi.exe -b 127.0.0.1:9003 -c "%batDir%php/php.ini"

start "nginx服务" /MIN  /D "%batDir%nginx" nginx.exe



然后nginx的

http {
#window 不能派生子进程,仅仅能人工配 PHP_FCGI_CHILDREN 在window不起作用的
upstream fastcgi_backend {
server 127.0.0.1:9000;
server 127.0.0.1:9001;
server 127.0.0.1:9002;
server 127.0.0.1:9003;
}


弄一个备用server



域名配置时,使用转发到备用server


server {
listen       80;
server_name  q.qq;
access_log ./../log/q.qq.access.txt;
root d:/web/www;

location ~ \.php$ {
fastcgi_pass   fastcgi_backend;
}
}


ok.同一时候打开4个php是能够独立解析了,并行,可是5个呢?第5个还是要等等吧..........

posted @ 2017-07-04 21:04  lytwajue  阅读(1533)  评论(0编辑  收藏  举报