Re: Application Scope variables ?
From: aa (aa_at_virgin.net)
Date: 09/21/04
- Next message: aa: "Re: Application Scope variables ?"
- Previous message: Michael Fesser: "Re: Writing PHP with 'sessioned' and 'unsessioned' behaviour."
- In reply to: Gordon Burditt: "Re: Application Scope variables ?"
- Next in thread: Tim Van Wassenhove: "Re: Application Scope variables ?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Tue, 21 Sep 2004 21:08:22 +0100
"Does ASP even guarantee that several sessions each doing the equivalent of
$hitcount++; "
ASP' application is an object with a method "lock" to handle attempts to
change a variable from two or more sessions at a time. I do not know is it
guaranties something, but it works.
So if there is nothing like that in PHP - thanks - you saved me time lokinmg
for something which is not there.
"Gordon Burditt" <gordonb.a6hin@burditt.org> wrote in message
news:cipte4$qal@library2.airnews.net...
> >Just to stream the discussion up - how a page hit conter in implemented
in PHP?
>
> I'd use a database:
> UPDATE hit_count set count=count+1, last=now() where url='...';
> or if I really wanted details for each hit, add an entry to a hit_log
table,
> logging time, URL, and perhaps other stuff like IP, user name, session,
referrer, etc.
>
> >In ASP you increment a relative Application scope variable every time a
page is
> >requested. This veraible is accessible from any session.
>
> Besides hit counters, of what *USE* is such a variable?
> It can be accessed from (and messed up by) so many different
> concurrent sessions that any significant read/write use will have
> to worry about locking issues. Does ASP even guarantee that several
> sessions each doing the equivalent of $hitcount++; will be atomic
> and not lose counts (on a multiprocessor machine, possibly)?
>
> Assume $last_server is the ID of the last waitperson assigned to a table
(and
> it's one of those "Application-scope" variables.
> IDs run from 1 to $max_server. You want to assign them in turn,
round-robin.
>
> $last_server++;
> if ($last_server > $max_server) { $last_server = 1; }
> $this_server = $last_server;
> ... assign $this_server to serve the food for this order ...
>
> Now, how do you write that (or its equivalent in ASP) so it's
> multi-session, multi-processor safe? You don't assign the same
> server two orders a row. You don't skip anyone. Not even if a bunch
> of orders come in simultaneously.
>
>
> I also wouldn't be too pleased to learn that I'd lose several days
> worth of changes to that variable (kept only in memory) if the
> machine crashed. In particular, losing a variable like 'next invoice
> number to assign' kept in memory only would be a real nuisance.
>
> >This variable is sitting in the memory as long as the Application (i.e.
the website) is
> >running.
>
> Which means you can lose it at any time if the Application is running.
>
> >If the Application is stopped, it fires an event "application_on_close"
and on this
> >event you write an application data to a file from which it can be
recovered when the
> >application is restarted.
>
> And if the application, or system, crashes? How often do you actually
intentionally
> shut down a web server (besides applying security patches)? In my
experience, this
> is MUCH less often than CPU fan failure or power supply failure.
>
> >How do I get the same effect in PHP?
>
> What do you need it for? I think it makes an unreliable hit counter and
it's not
> good for much else.
>
> Gordon L. Burditt
- Next message: aa: "Re: Application Scope variables ?"
- Previous message: Michael Fesser: "Re: Writing PHP with 'sessioned' and 'unsessioned' behaviour."
- In reply to: Gordon Burditt: "Re: Application Scope variables ?"
- Next in thread: Tim Van Wassenhove: "Re: Application Scope variables ?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|