PHP shares objects in multiple sessions

How can I have user A and user B have the same instance of the object? I guess it will be through two different sessions.

+4
source share
2 answers

One way is to serialize the object and then put it in a file or database to share it between requests. However, if two requests are executed exactly at the same time, each of them will have a different object for work, and the last request will be the only one that will be saved. Therefore, to prevent this, you will need some kind of locking mechanism.

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

+2
source

Checkout APC,

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

You can save the object in cache like this,

apc_store('my_key', $obj); 

and get from another page / session for example

 $obj = apc_fetch('my_key'); 
+3
source

All Articles