我不属于Perl领域,所以其中有些对我来说是新的。我正在运行安装了apache2和mod_fcgid软件包的Ubuntu Hardy LTS。我想让MT4在fcgid而不是mod-cgi下运行(对于普通的CGI,它似乎可以正常运行)。

我似乎什至无法获得一个简单的Perl脚本在fcgid下运行。我创建了一个简单的“ Hello World”应用程序,并包含了this previous question中的代码以测试FCGI是否正在运行。

我将脚本命名为HelloWorld.fcgi(当前,fcgid设置为仅处理.fcgi文件)。码:

#!/usr/bin/perl

use FCGI;

print "Content-type: text/html\n\n";
print "Hello world.\n\n";
my $request = FCGI::Request();
if ( $request->IsFastCGI ) {
    print "we're running under FastCGI!\n";
} else {
    print "plain old boring CGI\n";
}


当从命令行运行时,它会显示“ plain old boring ...”。当通过http请求调用apache时,我收到500 Internal Server错误,并且脚本的输出被打印到Apache错误日志中:

Content-type: text/html

Hello world.

we're running under FastCGI!
[Wed Dec 03 22:26:19 2008] [warn] (104)Connection reset by peer: mod_fcgid: read data from fastcgi server error.
[Wed Dec 03 22:26:19 2008] [error] [client 70.23.221.171] Premature end of script headers: HelloWorld.fcgi
[Wed Dec 03 22:26:25 2008] [notice] mod_fcgid: process /www/mt/HelloWorld.fcgi(14189) exit(communication error), terminated by calling exit(), return code: 0


当我运行相同代码的.cgi版本时,它工作正常。知道为什么脚本的输出将进入错误日志吗?在VirtualHost指令中,Apache config是默认的mod_fcgid config plus:

  ServerName test1.example.com
  DocumentRoot /www/example

  <Directory /www/example>
    AllowOverride None
    AddHandler cgi-script .cgi
    AddHandler fcgid-script .fcgi
    Options +ExecCGI +Includes +FollowSymLinks
  </Directory>

最佳答案

我使用CGI :: Fast比使用FCGI快得多,但是我认为想法是相同的。快速cgi的目标是一次加载程序,并针对每个请求循环循环。

FCGI的手册页中说:

use FCGI;

my $count = 0;
my $request = FCGI::Request();

while($request->Accept() >= 0) {
    print("Content-type: text/html\r\n\r\n", ++$count);
}


这意味着,必须先Accept请求,然后才能将任何内容打印回浏览器。

10-05 22:51