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