How to pre-open files in apache's processes

Xiao Lan <[email protected]>
Newsgroups gmane.comp.apache.mod-perl
Message-ID <[email protected]>
Hello,

I want to pre-open files in apache's processes.
So every modperl handlers will use the file handle directly, instead
of re-openning the files each time when the requesting is coming.

Currently I do it with:

package Fileopen;
use strict;
require Exporter;

our @ISA = qw(Exporter);
our @EXPORT = qw($filehandle);
our $filehandle;

open $filehandle,"<","/path/to/big.file" or die $!;  # open  for
reading only, the file itself is readable only.


1;


Then in startup.pl:

use Apache2::RequestRec ();
use Apache2::RequestIO ();
use Apache2::Request ();
use Fileopen;
# use others...

1;


Last in each handler:

package Myhandler;

use strict;
use Apache2::RequestRec ();
use Apache2::RequestIO ();
use Apache2::Const -compile => qw(OK);
use Apache2::Request ();
use Fileopen;

sub handler {
    my $r = shift;
    our $filehandle;  # exported from Fileopen
    # deal with $filehandle
    ...
}

1;


I'm not sure, am I going on the correct way for the purpose?
Thanks for the helps.

Regards.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.