You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Shibi NS <sh...@gmail.com> on 2010/04/13 20:23:18 UTC

Server Level Global Variable

I have requirement to maintain variables at server level say a
counter(something like server restart count) variable and time date, so if
particular event(say die on request handler) this counter increments by one
and time date variable updated to current system date and time.  Is there is
any way to do it  so all request process get access to this variable can be
updated by  Apache reques

--Shibi Ns--

Re: Server Level Global Variable

Posted by Perrin Harkins <ph...@gmail.com>.
On Tue, Apr 13, 2010 at 2:23 PM, Shibi NS <sh...@gmail.com> wrote:
> I have requirement to maintain variables at server level say a
> counter(something like server restart count) variable and time date, so if
> particular event(say die on request handler) this counter increments by one
> and time date variable updated to current system date and time.  Is there is
> any way to do it  so all request process get access to this variable can be
> updated by  Apache reques

No.  You can do it by using a database, a file, or shared memory with
one of the modules on CPAN.  Unless you have extreme performance
needs, I'd suggest just using a database, since you probably have one
already.

- Perrin

Re: Server Level Global Variable

Posted by Michael Ludwig <mi...@gmx.de>.
Shibi NS schrieb am 13.04.2010 um 23:53:18 (+0530):
[Server Level Global Variable]

> I have requirement to maintain variables at server level say
> a counter(something like server restart count) variable and
> time date

So you're aware of Apache2::ServerUtil#restart_count ?

> so if particular event(say die on request handler) this
> counter increments by one and time date variable updated to
> current system date and time.  Is there is any way to do it
> so all request process get access to this variable can be
> updated by  Apache reques

Well, I'm a bit surprised I can't find anything that looks
like it's intended for this very purpose, but if you scroll
through the perldoc for Apache2::ServerRec and get to the
"Unsupported API" section, you'll see "names" and
"wild_names", both of which could possibly *abused* to serve
your needs. Here's a registry script:

         \,,,/
         (o o)
-----oOOo-(_)-oOOo-----
use common::sense;
use Apache2::Const ();
use Apache2::ServerRec ();
use Data::Dumper;

my $r = shift;
my $s = $r->server;
my $ap_names  = $s->names;
my $ap_wnames = $s->wild_names;

$r->content_type('text/plain');
$r->print( Dumper $ap_names, $ap_wnames );
return Apache2::Const::OK;
-----------------------

The output is:

$VAR1 = bless( do{\(my $o = 136268856)}, 'APR::ArrayHeader' );
$VAR2 = bless( do{\(my $o = 136268896)}, 'APR::ArrayHeader' );

But I don't know how to continue: there's no interface to the
APR::ArrayHeader structure. So this won't work. And it would have
been a hack anyway.

You could consider using memcached or a similar mechanism. But
I agree Apache should have something to offer here. After all,
Apache's emphasis isn't on being lean and mean. Well, maybe I
just don't know where to look.

-- 
Michael Ludwig