tags:

views:

76

answers:

2

How can i have user A and user B has the same instance of an object? I guess this would be across two different sessions.

TIA.

+2  A: 

One way would be to serialize the object and then putting it in a file or a database to share it between requests. However if two request happen exactly at the same time, they will each have a different object to work with and the last request to finish will be the only one that will be saved. So you will need some kind of locking mechanism prevent that.

http://ca.php.net/manual/en/function.serialize.php

Laurent Bourgault-Roy
Lock by storing the serialization in a table having the locking userID in a field of the serialization record. Then lock with "Update ser set uid = ME where ME is NULL;", Check for getting the lock by selecting back, release the lock by nulling out the uid when updating the serialization.
Don
If two users are logged on at the same time, is the object they share synced? or is it like having the object in two differant states.
Jeremiah
It would be like having the object in two different state. Since every request happen in it's own process there is no easy way to share an in-memory object between to instance of a script.
Laurent Bourgault-Roy
A: 

Checkout APC,

http://www.php.net/manual/en/intro.apc.php

You can store the object to cache like this,

apc_store('my_key', $obj);

and retrieve from another page/session, like this,

$obj = apc_fetch('my_key');
ZZ Coder