我应该将 Perl 库和 CGI​​ 程序合并到一个 FastCGI 文件中吗?

发布于 2024-10-01 00:16:46 字数 477 浏览 2 评论 0原文

我正在重写 CGI 脚本以利用 fastcgi 模块。我的初始程序由两个脚本组成。一个“需要”另一个。在效率方面,我是否需要重新考虑整个“require”脚本并将它们合并到一个文件中?这些脚本可以总结如下:

脚本 A :

use FCGI;
# Do a lot of stuff and slurping (memory intensive)
sub use_my_slurped {
# Do sub here
}

sub use_my_slurped2 {
# Do sub here 
}

###############
# EOF A#
###############


Script B:
require A;

while (FCGI::accept >= 0) {
# main program functions
$blah = use_my_slurped (X,Y,Z)
print "Some HTML stuff $blah"; 
}

I am rewriting a CGI script to make use of fastcgi module. My initial program consists of two scripts. One "requires" the other. In terms of efficiency, do I need to rethink the whole "require" script and combine them both into one file? The scripts can be summarized as below:

Script A :

use FCGI;
# Do a lot of stuff and slurping (memory intensive)
sub use_my_slurped {
# Do sub here
}

sub use_my_slurped2 {
# Do sub here 
}

###############
# EOF A#
###############


Script B:
require A;

while (FCGI::accept >= 0) {
# main program functions
$blah = use_my_slurped (X,Y,Z)
print "Some HTML stuff $blah"; 
}

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

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

发布评论

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

评论(2

绳情 2024-10-08 00:16:46

首先,A 不是脚本,而是 Perl 库。

其次,FastCGI 可以在不进行修改的情况下优雅地处理这个问题。这取决于 A 是否是完全限定的文件名。

第三,只需很少的工作 A 就可以成为一个模块,然后一切都应该正常工作。

# A.pm
sub func1 {}
sub func2 {}

1;

进而

# B.cgi
use lib qw( /path/to/dir/containing/above );
use A;
# ...
my $blah = func1();

First off, A isn't a script but a perl library.

Second, FastCGI might handle this gracefully without modification. It depends on if A is a fully qualified filename or not.

Third, will very little work A could become a module, and then everything should Just Work.

# A.pm
sub func1 {}
sub func2 {}

1;

And then

# B.cgi
use lib qw( /path/to/dir/containing/above );
use A;
# ...
my $blah = func1();
抱着落日 2024-10-08 00:16:46

将它们作为单独的文件保存应该没有问题。 FastCGI 不需要为每个请求加载和编译库,因此启动时间并不像普通 CGI 中那么重要。除非你正在寻找可以做的事情,否则我可能会不管它。

但是,如果库是以某种奇怪的方式编写的,您需要每个请求加载一次,那就是另一回事了。

对于您的示例,我认为您需要将所有 FastCGI 内容移至同一个文件中。您将模块(例如 FCGI)加载到要使用该模块中的内容的文件中。

There shouldn't be a problem leaving them as separate files. FastCGI doesn't need to load and compile the library for every request, so start up time is not that big of a deal as it is in normal CGI. Unless you're looking for things to work on, I'd probably just leave it alone.

However, if the library was written in some weird way where you need to load it once per request, that's a different story.

For your example, I think you need to move all of the FastCGI stuff into the same file. You load modules, such as FCGI, in the file that you want to use stuff from that module.

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