0

I am attempting to access session variables set via php stored in memcached from node.

I would really like the format of the stored session data to be in JSON.

I found msgpack and that looked like it might do the job, however, a console.log of the session data within node reveals that items are seperated by little ? marks:

���user_id�1�company_id�1�fname�name�lname�lname�lactivity�S.7��login_st.... and so on

My php file

//serialize in a nice JSON FORMAT

ini_set('session.serialize_handler', 'msgpack');

//use MEMCACHED to save sessions

ini_set('session.save_handler', 'memcached');

//the port memcached is running on

ini_set('session.save_path', 'localhost:11211');

I am trying to access the php sessions from node, where I use JSON.parse however it always gets an invalid character error.

If anyone has any ideas I would be most grateful!

Grant

Grant
  • 105
  • 8

1 Answers1

1

Messagepack isn't JSON, so using JSON.parse on Messagepack's data won't work.

You should use this Node module which allows parsing Messagepack's objects in Node.

Example usage :

var msgpack = require('msgpack'); // import the node-msgpack module

var unpacked = msgpack.unpack(packed); // unpack the "packed" variable
  • I did originally try this, however I get the following problems on install: **[pastebin](http://pastebin.com/QYBWpVhr)** its the first time that I have had an error with npm packages. ive also tried, with the `nodedir=/path/to/node/` directive which results in:**[pastebin](http://pastebin.com/BhYXjcfJ)** thank you for your time. – Grant Mar 23 '14 at 10:08
  • so I finally got msgpack installed by uninstalling node and reinstalling the latest stable version. However when trying to unpack with: `var unpacked = msgpack.unpack(result)` I get `TypeError: First argument must be a Buffer`Thanks – Grant Mar 23 '14 at 11:07