Server Level Global Variable

Server Level Global Variable

am 13.04.2010 20:23:18 von Shibi NS

--00c09f971e7e0ff28a0484225be5
Content-Type: text/plain; charset=ISO-8859-1

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--

--00c09f971e7e0ff28a0484225be5
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

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


--Shibi Ns--


--00c09f971e7e0ff28a0484225be5--

Re: Server Level Global Variable

am 13.04.2010 21:37:35 von Michael Ludwig

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

Re: Server Level Global Variable

am 13.04.2010 22:12:28 von Perrin Harkins

On Tue, Apr 13, 2010 at 2:23 PM, Shibi NS wrote:
> I have requirement to maintain variables at server level say a
> counter(something like server restart count) variable and time date, so i=
f
> particular event(say die on request handler) this counter increments by o=
ne
> and time date variable updated to current system date and time.=A0 Is the=
re is
> any way to do it=A0 so all request process get access to this variable ca=
n be
> updated by=A0 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