mod_perl share variables across child processes
Asked Answered
H

1

6

I have a mod_perl system accepting API calls from different client systems Suppose in the child perl program I have calls like this which does some heavy processing

$conf{$client_id} = generate_client_conf($client_id); # returns a ref to a hash

I would like to re-use this variable $conf{$client_id} in other child processes How can I do this ?

The variables cannot be loaded at startup.pl ,but needs to be cached once it is generated

Headquarters answered 24/10, 2013 at 12:42 Comment(2)
You may want to look at memcached and associated Perl modules. This is not a strict answer to your problem (memcached is a separate process, not caching inside Apache), but may well solve your performance issue.Camilla
Memcached , means I will have to make a TCP connection everytime in the mod_perl script. I am not able to persist the Memcached handle tooHeadquarters
S
1

You should use Cache::FastMmap

In mod_perl, just open the cache at the global level in the appropriate module, which is executed as the server is starting and before it starts forking children, but you'll probably want to chmod or chown the file to the permissions of the apache process.

Spike answered 10/11, 2013 at 11:17 Comment(1)
This is an old thread, but I'm trying to use Cache::FastMmap in mod_perl. It isn't clear how to initialize it. If I create it in startup.pl it complains that the code can't work in threads. If I then just create an empty file (to use as the shared memory file) in startup.pl that also doesn't work. So is there a concrete example of using Cache::FastMmap with mod_perl (version 2 and with Apache 2.4)? Thanks.Evelyn

© 2022 - 2024 — McMap. All rights reserved.