douna4762 2018-09-02 19:08
浏览 46

Nodejs Memcached无法找到PHP存储

I've just set up memcached on my debian server to exchange sessions between nodejs (Chat Server) and PHP (Website). So this is how far I got right now.

I've configured PHP to save the session details in memcached and ran this script.

<?php
error_reporting(E_ALL);
session_start();
 $_SESSION['some'] = 'thing';
 echo session_id()."
";
 print_r($_SESSION);

Also i tried to get the data by memcached-tool

/usr/share/memcached/scripts/memcached-tool localhost:11211 dump

i got this output after some errors related to pear (I wont post them unless somebody says nodejs surprisingly uses pearl)

Dumping memcache contents

Number of buckets: 1 Number of items : 1 Dumping bucket 2 - 1 total items add memc.sess.etnq8q744bdc6srknrdu78a5e4 0 1535915171 17 some|s:5:"thing";

so i guess it worked so far. Now I wrote this nodejs script

const cookie = require('cookie');

const Memcached = require('memcached');
const PHPUnserialize = require('php-unserialize');

    var mem = new Memcached('127.0.0.1:11211');

    mem.set('foo', 'dass',100,function(err){
        console.log('Error1:'+err);
    });
    mem.get('foo', function(err, data) {
        console.log('Error:'+err);
        console.log('Data'+data);
    });

    var PHPSESSID = cookie.parse(socket.request.headers.cookie).P$
    console.log(PHPSESSID);

    mem.get(PHPSESSID, function(err, data){
        if(err) return console.error(err);
        if(data===false)return console.error('could not retreive $
        console.log('raw data:',data);
    });

unfortunately i get the value "dass" which i set before but all other are undefined

etnq8q744bdc6srknrdu78a5e4
output send
Error1:undefined
Error:undefined
Datadass
raw data: undefined

I Think there must be any difference about how or where i connect to the memcached server. But I can't find any code doing this. I also can't see the nodejs inserted values with memcached-tool

Those are only Cutouts. The full code and full output is here

code https://pastebin.com/3uQqZFai

output https://pastebin.com/991ebxfq

The code worked completely fine before adding memcached. Also it worlks now but the memcached part. Also i used the working client to connect to trigger the memcached part. And I also know this code is not perfekt. I still work on understanding that whole stuff. P

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
    • ¥15 如何在scanpy上做差异基因和通路富集?
    • ¥20 关于#硬件工程#的问题,请各位专家解答!
    • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
    • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
    • ¥30 截图中的mathematics程序转换成matlab
    • ¥15 动力学代码报错,维度不匹配
    • ¥15 Power query添加列问题
    • ¥50 Kubernetes&Fission&Eleasticsearch
    • ¥15 報錯:Person is not mapped,如何解決?