Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/299.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP custom session.serialize_处理程序JSON_Php_Json_Node.js_Session - Fatal编程技术网

PHP custom session.serialize_处理程序JSON

PHP custom session.serialize_处理程序JSON,php,json,node.js,session,Php,Json,Node.js,Session,我需要访问Node.js中的PHP会话,因此我认为一个好主意是使用memcached存储编码为JSON的会话,并在Node.js中对其进行解码 我知道我可以设置session.save\u handler=memcached,但是有没有办法设置session.serialize\u handler=some\u json\u handler?或者我必须自己使用会话\u设置\u保存\u处理程序对其进行编码 非常感谢您的帮助 我也有同样的要求。我正在使用tornado,需要用python访问php会

我需要访问Node.js中的PHP会话,因此我认为一个好主意是使用memcached存储编码为JSON的会话,并在Node.js中对其进行解码

我知道我可以设置
session.save\u handler=memcached
,但是有没有办法设置
session.serialize\u handler=some\u json\u handler
?或者我必须自己使用
会话\u设置\u保存\u处理程序对其进行编码


非常感谢您的帮助

我也有同样的要求。我正在使用tornado,需要用python访问php会话。 点击此链接
https://github.com/lboynton/memcached-json-session-save-handler/blob/master/library/Lboy/Session/SaveHandler/Memcached.php

希望这能有所帮助。

我已经将它与couchbase一起使用,至少是一个概念证明。您可能希望尝试此方法和node.js等效方法,这样您就可以看到正确的结果

代码位于phalcon中,因此可能对您的目的没有用处,但出于完整性考虑(其中
$this->\u instance()
返回couchbase/memcache实例)

和在会话处理程序中

public function read($sessionId){
    $data =  $this->_instance()->get($this->_getSessionId($sessionId), $this->getOption('lifetime'));
    if(!empty($data)){
        $data = json_decode($data, true);
        return \msgpack_pack($data);
    }
    return '';
}

public function write($sessionId, $data){
    session_decode($data);
    $serializedData = json_encode($_SESSION);
    $this->_instance()->save($this->_getSessionId($sessionId), $serializedData, $this->getOption('lifetime'));
}
在我拥有的时间内,我无法让msgpack与phalcon/couchbase/node完美配合,因为让会话正常工作只是很小的一部分,我还需要学习node,编写应用程序,以了解它是否达到了我们想要的效果;)

我之所以使用msgpack,是因为出于某种原因,我无法在php中使用session_encode(),可能是因为MVC实现

node JS的东西-它使用express,这是我第一次尝试node,所以在脑海中:)


我想你必须自己编写代码。我建议实现SessionHandler/SessionHandlerInterface(如果可能,PHP>5.4)——在我看来,这比注册简单的会话处理函数更干净@CBroe我使用的是php5.3.3。我可以像
session\u set\u save\u handler(数组($this,'open'),…
那样绑定它,以避免简单的函数
public function read($sessionId){
    $data =  $this->_instance()->get($this->_getSessionId($sessionId), $this->getOption('lifetime'));
    if(!empty($data)){
        $data = json_decode($data, true);
        return \msgpack_pack($data);
    }
    return '';
}

public function write($sessionId, $data){
    session_decode($data);
    $serializedData = json_encode($_SESSION);
    $this->_instance()->save($this->_getSessionId($sessionId), $serializedData, $this->getOption('lifetime'));
}
var memcache = require("memcache");
var client = new memcache.Client(11211, "localhost");
client.connect();

client.get("/sessions/"+req.cookies.PHPSESSID, function(error, result){
    if(typeof(error)==="undefined"){
         var session = JSON.parse(result);
        console.log('session : ',session);
        res.render('view/name', { title: 'Express' , sessionData: session});
    }