开发者

Should I combine my Perl library and CGI program into one file for FastCGI?

开发者 https://www.devze.com 2023-01-24 04:29 出处:网络
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\" sc

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 "Som开发者_高级运维e HTML stuff $blah"; 
}


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();


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消