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

发布于 2024-09-07 08:36:47 字数 1121 浏览 4 评论 0原文

我有一个用 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.perlincludes/

$lsincludes/

functions.cgifunctions.perl

I have a script that's written in perl, and executed as CGI. It works fine. Recently I have installed the mod_perl module into apache, and used the PerlModule ModPerl::Registry directive.

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>

I've read that using this I do not need to modify my cgi perl code. (I always use strict pragma, so don't worry about uninitialized global variables and stuff like that).

My original script still works as intended, except for one thing, files that I included with the require() function can no longer be resolved.

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

The directory structure works like this:

$ ls

script.cgi script.perl includes/

$ ls includes/

functions.cgi functions.perl

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

与之呼应 2024-09-14 08:36:47

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

META:记录一下,目前我们不使用 chdir() 进入脚本的目录,因为它会影响线程下的整个过程。 ModPerl::RegistryPrefork 应该由仅在 prefork MPM 下运行的用户使用。

因此,如果您使用 Apache2 的 prefork MPM,则应该尝试使用 ModPerl::RegistryPrefork。如果您使用的是工作程序、事件或窗口,则必须更改程序以不假设 cwd 是 perl 所在的目录。

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

META: document that for now we don't chdir() into the script's dir, because it affects the whole process under threads. ModPerl::RegistryPrefork should be used by those who run only under prefork MPM.

so, if you're using Apache2's prefork MPM, you should try using ModPerl::RegistryPrefork. If you're using worker, or event, or windows, you're going to have to change your program to not assume that the cwd is the directory that that the perl is sitting in.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文