How to share a session with a Erlang application
I need to create a chat in Erlang.
Is there a way to share the session between PHP and Erl开发者_如何学运维ang applications ?
Yes, it would require several conditions:
- Both Erlang & PHP should rely on identifying sessions or HTTP with a cookie name, exchanged over the same domain (or wildcard-domain).
- The should both be able to read the format in which the session is stored (json comes to mind, or peb_connect() in php )
- 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)
- 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
精彩评论