Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

How to implement memcache for handling session storage?

I need to implement Memcache session storage so that i could authorize websockets (ratchet). I'm a beginner in web dev, so i have some hard time understanding how libraries, classes, etc are being implemented into the project.

My project is based on Vokuro. What i want to achieve is, session storage in memcache rather than native phalcon adapter. I've seen this memcache adapter, but i don't understand how to implement it in my project.

Also, finally when i get adapter memcache adapter functioning, will i have to modify Vokuro's authentication classes or will it still work as it was with native adapter.

Thanks in advance!



12.3k
Accepted
answer

Register the incubator namespace in bootstrap

$loader = new Phalcon\Loader();

$loader->registerNamespaces(array(
    'Phalcon' => '/path/to/incubator/Library/Phalcon/'
));

$loader->register();

Set the session details in bootstrap and phalcon will do the rest.

$di->set('session', function(){

    $memcache = new Phalcon\Session\Adapter\Memcache(array(
        'host'          => '127.0.0.1',     // mandatory
        'port'          => 11211,           // optional (standard: 11211)
        'lifetime'      => 8600,            // optional (standard: 8600)
        'prefix'        => 'my-app'         // optional (standard: [empty_string]), means memcache key is my-app_31231jkfsdfdsfds3
        'persistent'    => false            // optional (standard: false)
    ));
    $memcache->start();
    return $memcache;
});

https://github.com/phalcon/incubator

https://github.com/phalcon/incubator/tree/master/Library/Phalcon/Session/Adapter