[UPHPU] Class and Object Storage

Justin Giboney giboney at giboneydesigns.com
Sat Feb 16 22:59:12 MST 2008

Is there a way to use singleton [1] classes with webpages?

Basically I want to be able to have classes that are shared for multiple 
users, so that the class and objects don't have to be recreated.

They way I understand things now, are that all of your classes are 
destroyed (or at least unavailable) after the web server sends the page.

I have used memcached [2], but it adds a lot of code for classes all the 
singleton classes that I need. Plus, not all hosts support memcached, 
which makes the program less portable.

For those of you that don't think it is necessary, or that want more 
details, read on.
    I have a GUID [3] class that produces GUIDs for me. This class is 
set up to only allow one person through at a time (at least I hope), so 
that the same GUID will never be replicated. I only can have one object 
of this class in existence at a time or else the the same GUID could be 
created if both were hit at the same time.

    Why a GUID? A GUID is necessary to be able to call things from the 
cache. Auto_increment on a dbms uses the same set of values for each 
table. That number cannot be used to reference objects in a cache, so 
something more detailed needs to be used.

    Why a cache? A cache allows me to not hit the database as often. 
This speeds up the web server.

    Why OO [4]? Because it is clean.


Justin Giboney

[1] Singleton: http://en.wikipedia.org/wiki/Singleton_pattern
[2] Memcached: http://www.danga.com/memcached/
[3] GUID: http://en.wikipedia.org/wiki/GUID
[4] OO: http://en.wikipedia.org/wiki/Object-oriented_programming

More information about the UPHPU mailing list