[UPHPU] Class and Object Storage

Walt Haas haas at xmission.com
Sun Feb 17 11:23:31 MST 2008


Justin Giboney wrote:
> 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.
>

I'm trying to understand what you want to do.  From what you said I'm 
guessing that you want a portable way to generate unique keys for a 
cache, and are looking to some implementation of UUID to do this. [see 
http://tools.ietf.org/html/rfc4122]

What makes a UUID unique is statistics, ie. the odds of generating the 
same UUID twice is insignificantly small.  In order to achieve this, you 
need to look toward the quality of randomness that goes into the 
generation of the UUID.  There are many pseudo-random number generators 
that are actually very predictable so don't really accomplish the 
desired goal of uniqueness.  Keeping one instance of the UUID generator 
class around may or may not accomplish this goal, depending on the 
underlying random number generator [see http://www.random.org/].

So  if I understand what you're trying to do, you need to find a 
portable way to generate true randomness.

-- Walt



More information about the UPHPU mailing list