NYCPHP Meetup

NYPHP.org

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

Hans Zaunere zaunere at yahoo.com
Sat Mar 15 14:13:50 EST 2003


--- Ophir Prusak <ophir at prusak.com> wrote:
> Hi All,
> 
> I'm looking for the best way to store non-critical frequently updated data
> that needs to be shared across all php processes (on a single server).
> Please notice I say frequently updated. If I'm just storing something that
> only changes once every N requests (where N is a large number) then I'd
> just use the file system since the OS caches that anyways.

Yeah, N would have to be very large IMO to beat out kernel caching.

> 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.
> 
> Has anyone done anything like this ?

Basically it looks like you need application variables.  The best way to do
this is probably with shared memory and semaphores if available.  Although
PHP's extension falls short abit in some area for this, I've written a couple
classes that have worked well for me:

http://parsec.nyphp.org/pVar.inc
http://parsec.nyphp.org/pApp.psh

pVar is the main class, with pApp being a shell script to create and manage a
particular application.  It's a bit rough, and you could probably just get
away with pVar.inc.  You're welcome to rip/hack any of that code as needed
and let me know if you run into any questions.

Best,

H




More information about the talk mailing list