NYCPHP Meetup

[nycphp-talk] Using shared data at the server level

Steve Manes smanes at magpie.com
Sun Mar 16 14:18:12 EST 2003


>For example, lets say I wanted to have a page counter on every page.
>Ideally, I'd just have a variable which is read/write by any php process on
>the server. Something like this:
>
>$my_super_global ++;
>print "this is page view $my_super_global";
>
>One way is to use the file system.
>This or course is pretty simple, but since the file needs to be updated
>every single request, I'm thinking it would be faster to use memory.

This will bind your web application to a single physical web server 
though.  For fluffy stuff that doesn't really matter all that much, like a 
page counter, I'd serve the count from a static cache, refreshing it every 
X hours from an asynchronous script.  In fact, I might have the script do 
that via an access log scan rather than having the web server update the 
database at every page load.

mod_perl has Apache::Storable for maintaining serialized, persistent data 
across connections.  There's a freshmeat knock-off of Storable for PHP but 
it sounds like it uses disk storage while I believe that Apache::Storable 
freezes structures in memory and writes them to disk on request:

http://freshmeat.net/projects/storable/?topic_id=44%2C809%2C42





More information about the talk mailing list