Apache FastCGI PHP中FastCgiExternalServer和FastCgiServer的区别?

时间:2016-05-06 22:00:01

标签: php apache fastcgi mod-fastcgi

请允许我声明我是FastCGI的新手。我的OS X机器上有MAMP的Apache。默认的PHP处理程序是Apache Handler 2.0(libphp5.so)。我想更改为FastCGI并按照此处的答案:How to configure Apache to run PHP as FastCGI on Ubuntu 12.04 via terminal?

我在httpd.conf的末尾添加了以下内容:

<IfModule mod_fastcgi.c>
   AddHandler php5.fcgi .php
   Action php5.fcgi /php5.fcgi
   Alias /php5.fcgi /Applications/MAMP/fcgi-bin/php5.fcgi
   FastCgiServer /Applications/MAMP/fcgi-bin/php5.fcgi -socket /Applications/MAMP/tmp/php-fcgi/php5-fpm.sock -pass-header Authorization -idle-timeout 3600
   #FastCgiExternalServer /Applications/MAMP/fcgi-bin/php5.fcgi -socket /Applications/MAMP/tmp/php-fcgi/php5-fpm.sock -pass-header Authorization -idle-timeout 3600
   <Directory /Applications/MAMP/fcgi-bin>
       Order allow,deny
         Allow from all
   </Directory> 
</IfModule>

但是,正如您所看到的,FastCgiExternalServer已被注释掉。相反,我不得不使用FastCgiServer因为Apache在尝试请求页面时给了我以下错误:

  

[Fri May 06 23:25:22 2016] [错误] [client :: 1](2)没有这样的文件或目录:FastCGI:无法连接到服务器“/ Applications / MAMP / fcgi-bin / php5 .fcgi“:connect()失败

     

[星期五06月23日23:25:22 2016] [错误] [client :: 1] FastCGI:从服务器收到的不完整标题(0字节)“/Applications/MAMP/fcgi-bin/php5.fcgi"

/Applications/MAMP/fcgi-bin/php5.fcgi存在,其内容为:

#!/bin/bash
PHP_CGI=/Applications/MAMP/bin/php/php5.6.2/bin/php-cgi
exec $PHP_CGI

FastCgiServerFastCgiExternalServer之间有什么区别?为什么FastCgiExternalServer在我的案例中不起作用,但FastCgiServer有效?

2 个答案:

答案 0 :(得分:11)

FastCgiServer是一个服务器,mod_fastcgi将对其进行进程管理 - 上下旋转实例并为其提供一个unix域套接字来监听。启动fastcgi服务器无需外部操作。

FastCgiExternalServer是mod_fastcgi不会对其进行任何进程管理的服务器 - 它只会触及您告诉它使用的转发或转发请求/响应的unix或TCP套接字。你或httpd之外的一些守护进程必须启动一些东西来监听列出的套接字。最基本的方法是'fcgistarter'实用程序,其他选项是php-fpm。

答案 1 :(得分:1)

If performance is reason, I would say use Apache with fcgid. This is considered better for performance. To deal with performance, mod_fcgid starts multiple instances of CGI programs to handle concurrent requests. This is alternate to mod_php for PHP developers, giving higher performance. This article I found is great resource to learn

http://2bits.com/articles/apache-fcgid-acceptable-performance-and-better-resource-utilization.html