Justin Giboney wrote:
Alvaro Carrasco wrote:
Since PHP is stateless by design, you cannot maintain an object alive past one request. In PHP, everything is created and then destroyed on every request. The only thing you can do is save the contents of the object (possibly by serializing it) and re-create it on the next request. Have you profiled the application? Instantiating a couple of objects is not generally an expensive operation (compared to other things), so is it really such a big problem to have object instantiated on every request.

If you really, REALLY want to keep an instantiated object across requests, do a google search for "php bananas" or "php script running machine". I don't know if it's usable though.

Alvaro
I think that I can do it with memcached, but as said before that is a lot more overhead. It isn't the processing time to create objects that bothers me, it is the additional creation of an object that should not ever have two objects of that type at the same time in existence ever.

Thanks,

Justin Giboney

memcached serializes anything that is not a string or an integer. There is no other way. You just can't do it using objects on a stateless platform. But there are usually ways of achieving the desired behavior without keeping objects alive across requests. Why does the object need to be unique? Do you even need an "object"? You could just have a function (or method) that when it creates a UUID it saves it to the database so it doesn't give out the same one again (still seems unnecessary since it should never generate the same UUID).

Alvaro

_______________________________________________

UPHPU mailing list
[email protected]
http://uphpu.org/mailman/listinfo/uphpu
IRC: #uphpu on irc.freenode.net

Reply via email to