3

I am trying to share session information between our main PHP app and node.js

We currently use a database backend for session storage, because we have several web servers that can handle a request.

Is anyone aware of any solutions for accessing session data from node.js? The only ones I can see use redis or memcache, but we cannot change the method for storing session data.

2
  • If you can't change the method, then surely your only option is to retrieve the session data from the database and parse it in Node? Commented Jul 16, 2014 at 12:05
  • Yes, I could write that, I just was wondering if someone has done it before. Commented Jul 16, 2014 at 13:39

1 Answer 1

2

You would have to use a common format, such as JSON or one of your own invention. Let's assume JSON for convenience.

On the PHP side you will need to register your own session handler.

Set session.name to something less PHP specific, for example SESSID instead of PHPSESSID.

Set session.serialize_handler to php_serialize. In the write() method cast the incoming $data into JSON by first calling unserialize() on it, then calling json_encode() and set the re-encoded data in your database.

Similarly, the read() method should extract the session data from your database (given the value of the ID stored in the SESSID cookie), call json_decode() on it, then serialize it and return that string.

Might I suggest a fast, scalable, and reliable database such as Aerospike. I am, however, biased.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.