[nycphp-talk] Something better than session variables?
Hans Zaunere
hans at nyphp.org
Thu Jun 12 16:07:11 EDT 2003
--- Peter Balogh <palexanderbalogh at yahoo.com> wrote:
> Hello all--
>
> We have multiple users accessing a big tree of data that's very
> expensive to calculate each time. Ideally, it would be great to have
> the tree drawn once and then have all the other users access it as
> though it were a global SESSION variable visible to all users.
Hmmm...
> First of all, is there such a thing as a SESSION variable that's
> visible to all?
Sure; application variables, as mentioned. But the reason I say 'Hmmm' is
because application variables, regardless of how they are stored/implemented,
probably aren't the best way to go for large amounts of data. If you're
dealing with a big tree of data, and the issue is the expense of calculating
it for every request, I'd very much prefer using it in a cooked format.
For instance, every 1000 hits (or time based, doesn't matter) a special query
is run that cooks the raw data (the large set) into a calculated, more
manageable form. This cooked form is then stored in an optimized database
schema, or even HEAP tables, for example, if you're really worried. Some
call it a data mart, others data mining, and still other's just logical
architecture. We do it here on a nightly basis for much of our data, and
then several times a day for more volitale items.
> And then, to send the pie even further into the sky, is there a way to
> have a SESSION variable that's held in RAM instead of written to a flat
> file? (Yes, I'm getting greedy in terms of speeding things up.)
Sure. This, again, is essentially an application variable (in other
languages, they are stored in RAM by default). If you wanted true SESSION
variables (per user) to be stored in RAM, then you can use PHP's
session_handler functions. For application scope, shared memory is always
fun:
http://phpnow.net/src/
I haven't gotten around to finishing it yet, but you're welcome to use
whatever. Also, don't forget the kernel will cache files for you, which is
unbeatable as far as performance (especially with small amounts of data).
Or, implement application variables via MySQL - persistent connections,
indexed HEAP tables, and queries based on integers is damn hard to beat.
H
=====
Hans Zaunere
President, New York PHP
http://nyphp.org
hans at nyphp.org
More information about the talk
mailing list