Page 1 of 1
Sharing variables between sessions on same server
Posted: Thu Jul 17, 2008 4:49 pm
by thyrsus
I am creating a large multi-server app. My php running under Apache communicates through TCP/IP to a data server on another machine. To increase performance I cache a lot of data in associative arrays that I store in session variables so that it persists between pages. This requires all that data to be be serialized/unserialized at each page display. Also, my app is multi-user. It would be great if I didn't need to go to the data server for data that has already been cached by another user.
Are there any libraries or features that would allow in-memory variables to be scoped to the Apache server level so that they can be shared between sessions and also to avoid session serialization? Obviously, a shared semaphore or locking is required to prevent conflicts.
Thanks!!
Re: Sharing variables between sessions on same server
Posted: Thu Jul 17, 2008 5:54 pm
by pickle
Why are you serializing the arrays? They'll work just fine if you place them right in $_SESSION.
It looks like what you want is a data cache on the webserver so it doesn't need to access the data server. I know this kind of goes against the point of having a separate data & web server, but why not store the data you want to cache on the web sever?
Re: Sharing variables between sessions on same server
Posted: Thu Jul 17, 2008 6:59 pm
by thyrsus
I am not serializing the arrays myself. I AM putting them in $_SESSION, which is automatically serialized by PHP.
My data server is a semantic data server/inference engine. In addition to saving transmission delay, caching also eliminates re-inferencing. A local copy of the data server is not sufficient, I'd like to keep the data in PHP variable form between page sends.
Re: Sharing variables between sessions on same server
Posted: Thu Jul 17, 2008 7:10 pm
by WebbieDave
If your configuration affords APC, you can look into
apc_store and related functions.
Re: Sharing variables between sessions on same server
Posted: Fri Jul 18, 2008 9:55 am
by pickle
PHP doesn't exist between page sends. You'll have to store the data outside of a PHP variable.
Re: Sharing variables between sessions on same server
Posted: Fri Jul 18, 2008 3:10 pm
by thyrsus
APC IS the solution. Thank you very much for the help!!
It allows data to be cached and shared between users. It has limitations -- the cached data needs to have a simple structure -- but serialization before storing solves that.
The data is stored under keys. I can use my object ID as the key. This way I only need to unserialize/serialize the specific objects I need rather than the whole $_SESSION.
Re: Sharing variables between sessions on same server
Posted: Thu Dec 04, 2008 8:59 pm
by lhphp
i also think APC should be a good choice