Sometimes Rails and PHP applications must live side by side in harmony, which can mean sharing session data between them. Here’s one way this can be achieved with very little modification on the PHP side. First make sure your PHP application is using memcached for session storage:
If you’re interested in seeing how the PHP data gets serialized, take the value of the PHPSESSID cookie and perform a GET request in a memcached telnet session:
$ telnet localhost 11211
Connected to localhost.
Escape character is '^]'.
VALUE a29ajb8go3bkm6r6k2qu4hv3d5 0 298
There are a few Ruby libraries out there which can speak the language of PHP serialization. I’ve chosen Thomas Hurst’s php-serialize. Note that I’ve linked to my fork which also supports . characters in array keys. Add that to your Gemfile, and then include the following middleware in your Rails application.
Now you can use this session store in session_store.rb: