linux – 一个php-fastcgi进程阻止所有其他PHP请求

前端之家收集整理的这篇文章主要介绍了linux – 一个php-fastcgi进程阻止所有其他PHP请求前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我最近切换到 PHP的FastCGI设置(Apache2-worker和mod_fcgid).
但是,当单个PHP脚本非常繁忙时,它似乎会阻止所有其他PHP请求.
我的配置会出什么问题?

我使用mod_fcgid的主要原因是控制PHP内存使用量.使用mod_PHP,所有单独的Apache forks在服务PHP后都会在内存中增长.

我也转而使用apache2-worker模型,因为在Apache之外存在所有线程不安全的PHP代码.

我的FastCGI脚本如下所示:

  1. #!/bin/sh
  2. #export PHPRC=/etc/PHP/fastcgi/
  3. export PHP_FCGI_CHILDREN=5
  4. export PHP_FCGI_MAX_REQUESTS=5000
  5.  
  6. global_root=/srv/www/vhosts.d/
  7. exec /usr/bin/php-cgi5 \
  8. -d open_basedir=$global_root:/tmp:/usr/share/PHP5:/var/lib/PHP5 \
  9. -d disable_functions="exec,shell_exec,system"

我的Apache配置如下所示:

  1. <IfModule fcgid_module>
  2. FcgidIPCDir /var/lib/apache2/fcgid/
  3. FcgidProcessTableFile /var/lib/apache2/fcgid/shm
  4. FcgidMaxProcessesPerClass 1
  5. FcgidInitialEnv RAILS_ENV production
  6. FcgidioTimeout 600
  7. AddHandler fcgid-script .fcgi
  8.  
  9. FcgidConnectTimeout 20
  10. MaxRequestLen 16777216
  11.  
  12. <FilesMatch "\.PHP$">
  13. AddHandler fcgid-script .PHP
  14. Options +ExecCGI
  15. FcgidWrapper /srv/www/cgi-bin/PHP5-wrapper.sh .PHP
  16. </FilesMatch>
  17. DirectoryIndex index.PHP
  18. </IfModule>

解决方法

找到答案: https://stackoverflow.com/questions/598444/how-to-share-apc-cache-between-several-php-processes-when-running-under-fastcgi/1094068#1094068

问题不是PHP,而是mod_fcgid.虽然PHP会产生多个孩子,但mod_fcgid对此一无所知,并且会为每个孩子提供一个请求.因此,当使用FcgidMaxProcessesPerClass 1时,所有PHP执行都会在彼此之后发生. *

提出的解决方
链接到:http://www.brandonturner.net/blog/2009/07/fastcgi_with_php_opcode_cache/解释了如何使用没有此限制的mod_fastcgi.它会向同一个孩子发送多个请求.

[*]请注意,不使用FcgidMaxProcessesPerClass 1会导致许多单独的PHP,ruby等实例.虽然它们都能够在单个进程内部处理许多请求.

因此,一个新的Apache配置使用PHP与fastcgi:

  1. <IfModule mod_fastcgi.c>
  2.  
  3. # Needed for for suEXEC: FastCgiWrapper On
  4. FastCgiConfig -idle-timeout 20 -maxClassProcesses 1 -initial-env RAILS_ENV=production
  5. FastCgiIpcDir /var/lib/apache2/fastcgi
  6.  
  7. AddHandler PHP5-fcgi .PHP
  8. Action PHP5-fcgi /.fcgi-bin/PHP5-wrapper.sh
  9. DirectoryIndex index.PHP
  10.  
  11. ScriptAlias /.fcgi-bin/ /srv/www/cgi-bin/
  12. <Location "/.fcgi-bin/PHP5-wrapper.sh">
  13. Order Deny,Allow
  14. Deny from All
  15. #Allow from all
  16. Allow from env=REDIRECT_STATUS
  17. Options ExecCGI
  18. SetHandler fastcgi-script
  19. </Location>
  20.  
  21. # Startup PHP directly
  22. FastCgiServer /srv/www/cgi-bin/PHP5-wrapper.sh
  23.  
  24. # Support dynamic startup
  25. AddHandler fastcgi-script fcg fcgi fpl
  26. </IfModule>

猜你在找的Linux相关文章