Can you confirm the error you are encountering using your current method ?

I would like to understand what you are trying to achieve by having a global 
file handle - do you want to have modular code or does the content of the file 
somehow determine which handler to be used ?

You can have modular code by keeping the open in a init method in your package, 
push the package in @ISA and call SUPER::init from all the handler methods.


I hope you do realize the actual opening of the file doesn't take any 
appreciable amount of resources unless it is over a NFS over WAN.




- Mithun


----- Original Message -----
From:Xiao Lan <practicalp...@gmail.com>
To:modperl@perl.apache.org
Cc:
Sent:Wednesday, December 1, 2010 7:58:32 AM
Subject:How to pre-open files in apache's processes

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.



      

Reply via email to