Re: Application Scope variables ?

From: aa (aa_at_virgin.net)
Date: 09/21/04


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



Relevant Pages

  • Re: Application Scope variables ?
    ... ASP' application is an object with a method "lock" to handle attempts to ... change a variable from two or more sessions at a time. ... So if there is nothing like that in PHP - thanks - you saved me time lokinmg ... Does ASP even guarantee that several ...
    (alt.php)
  • Re: Page Hierarchy confusion...
    ... > VB.NET as your supporting language, you have to take another step back ... > There are also a lot of ASP to ASP.NET books out there that are invaluable ... > Side Note, sessions arent't all that bad anymore, you can have them managed ... >> Product info is persisted by using hidden fields. ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Using GLOBAL.ASAX with Classic ASP?
    ... to the SQL provider for sessions it won't work at all). ... Your statement on the SQL provider is not applicable to our sitiation. ... I would prefer much more to workaround the ASP issue I have with ASP alone. ... (just register the last request date/time count for all sessions and count ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Application Scope variables ?
    ... >> I am migrating to PHP from ASP where there are the Application Scope ... Sessions are not the same as application scope, ...
    (alt.php)
  • Re: Application Scope variables ?
    ... >> I am migrating to PHP from ASP where there are the Application Scope ... Sessions are not the same as application scope, ...
    (comp.lang.php)