mod_perl处理包含路径的方式与cgi不同?

时间:2010-06-28 22:10:51

标签: perl apache cgi mod-perl mod-perl2

我有一个用perl编写的脚本,并作为CGI执行。它工作正常。最近我将mod_perl模块安装到apache中,并使用了PerlModule ModPerl :: Registry指令。

PerlModule ModPerl::Registry
PerlModule CGI
PerlSendHeader On

Alias /perl/ /real/path/to/perl/scripts/
<Location /perl>
SetHandler  perl-script
PerlHandler ModPerl::Registry
Options ExecCGI
</Location>

<Files *.perl>
SetHandler  perl-script
PerlHandler ModPerl::Registry
Options ExecCGI
</Files>

我已经读过使用这个我不需要修改我的cgi perl代码。 (我总是使用严格的编译指示,所以不要担心未初始化的全局变量和类似的东西)。

我的原始脚本仍然按预期工作,除了一件事,我在require()函数中包含的文件无法再解析。

script.cgi:

#!/usr/bin/perl -w
use strict;
use CGI qw(:standard Vars);
require "includes/functions.cgi";

#blah blah, more stuff

script.perl

#!/usr/bin/perl -w
use strict;
use CGI qw(:standard Vars);
require "includes/functions.perl"; # <---- Returns error:  Can't locate includes/functions.perl in @INC
#blah blah, more stuff

目录结构的工作方式如下:

$ ls

script.cgi script.perl包含/

$ ls包含/

functions.cgi functions.perl

1 个答案:

答案 0 :(得分:2)

来自:http://perl.apache.org/docs/2.0/api/ModPerl/Registry.html

META:文件说现在我们没有chdir()进入脚本的目录,因为它会影响线程下的整个进程。只有在prefork MPM下运行的人才能使用ModPerl :: RegistryPrefork。

所以,如果你正在使用Apache2的prefork MPM,你应该尝试使用ModPerl :: RegistryPrefork。如果你正在使用worker,event或windows,你将不得不改变你的程序,不要认为cwd是perl所在的目录。