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脚本如下所示: #!/bin/sh #export PHPRC=/etc/php/fastcgi/ export PHP_FCGI_CHILDREN=5 export PHP_FCGI_MAX_REQUESTS=5000 global_root=/srv/www/vhosts.d/ exec /usr/bin/php-cgi5 -d open_basedir=$global_root:/tmp:/usr/share/php5:/var/lib/php5 -d disable_functions="exec,shell_exec,system" 我的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执行都会在彼此之后发生. * 提出的解决方案 [*]请注意,不使用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> (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |