Re: Application Scope variables ?
From: Gordon Burditt (gordonb.a6hin_at_burditt.org)
Date: 09/21/04
- Next message: steve: "Re: Re: reapir mysql table from php"
- Previous message: Tony Marston: "Re: Application Scope variables ?"
- In reply to: aa: "Re: Application Scope variables ?"
- Next in thread: aa: "Re: Application Scope variables ?"
- Reply: aa: "Re: Application Scope variables ?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 21 Sep 2004 18:55:00 GMT
>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: steve: "Re: Re: reapir mysql table from php"
- Previous message: Tony Marston: "Re: Application Scope variables ?"
- In reply to: aa: "Re: Application Scope variables ?"
- Next in thread: aa: "Re: Application Scope variables ?"
- Reply: aa: "Re: Application Scope variables ?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|