views:

79

answers:

1

I need to create a chat in Erlang.

Is there a way to share the session between PHP and Erlang applications ?

+2  A: 

Yes, it would require several conditions:

  1. Both Erlang & PHP should rely on identifying sessions or HTTP with a cookie name, exchanged over the same domain (or wildcard-domain).
  2. The should both be able to read the format in which the session is stored (json comes to mind, or peb_connect() in php )
  3. You should only store 'simple' structures in the session, which both can understand (arrays, hashmaps,, strings, integers, anonymous objects would be pushing it a bit)
  4. They should use a locking mechanism for read/writes that both can use (otherwise you have the chance new values are overwritten with stale data)

For PHP this means you should write your own handler for a session (see http://nl2.php.net/manual/en/function.session-set-save-handler.php), as far as I gather Erlang can use the same thing (well, the Erlang implementation is up to you).

The Erlang / PHP bridge may be used, but strictly speaking it is not necessary, it could save some work though.

Also of note: http://code.google.com/p/mypeb/wiki/ErlangAsSessionStorageForPHP

Wrikken
I would add that you need some kind of session store. I wouldn't recommend using the cookie. Instead you can should use a database which has the added effect if it's an RDBMS of handling the locking for you.
Jeremy Wall
Indeed: filesystem, database or memcache (cas!) are the usual suspects, all with well documented language-agnostic locking mechanisms.
Wrikken