我最近切换到
PHP的FastCGI设置(Apache2-worker和mod_fcgid).
但是,当单个PHP脚本非常繁忙时,它似乎会阻止所有其他PHP请求.
我的配置会出什么问题?
但是,当单个PHP脚本非常繁忙时,它似乎会阻止所有其他PHP请求.
我的配置会出什么问题?
我使用mod_fcgid的主要原因是控制PHP内存使用量.使用mod_PHP,所有单独的Apache forks在服务PHP后都会在内存中增长.
我也转而使用apache2-worker模型,因为在Apache之外存在所有线程不安全的PHP代码.
我的FastCGI脚本如下所示:
我的Apache配置如下所示:
- <IfModule fcgid_module>
- FcgidIPCDir /var/lib/apache2/fcgid/
- FcgidProcessTableFile /var/lib/apache2/fcgid/shm
- FcgidMaxProcessesPerClass 1
- FcgidInitialEnv RAILS_ENV production
- FcgidioTimeout 600
- AddHandler fcgid-script .fcgi
- FcgidConnectTimeout 20
- MaxRequestLen 16777216
- <FilesMatch "\.PHP$">
- AddHandler fcgid-script .PHP
- Options +ExecCGI
- FcgidWrapper /srv/www/cgi-bin/PHP5-wrapper.sh .PHP
- </FilesMatch>
- DirectoryIndex index.PHP
- </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:
- <IfModule mod_fastcgi.c>
- # Needed for for suEXEC: FastCgiWrapper On
- FastCgiConfig -idle-timeout 20 -maxClassProcesses 1 -initial-env RAILS_ENV=production
- FastCgiIpcDir /var/lib/apache2/fastcgi
- AddHandler PHP5-fcgi .PHP
- Action PHP5-fcgi /.fcgi-bin/PHP5-wrapper.sh
- DirectoryIndex index.PHP
- ScriptAlias /.fcgi-bin/ /srv/www/cgi-bin/
- <Location "/.fcgi-bin/PHP5-wrapper.sh">
- Order Deny,Allow
- Deny from All
- #Allow from all
- Allow from env=REDIRECT_STATUS
- Options ExecCGI
- SetHandler fastcgi-script
- </Location>
- # Startup PHP directly
- FastCgiServer /srv/www/cgi-bin/PHP5-wrapper.sh
- # Support dynamic startup
- AddHandler fastcgi-script fcg fcgi fpl
- </IfModule>