3

I am using Ratchet to create WebSocket for my app but I want to use session provider to know who is each connection that connect. Here is a documentation for it http://socketo.me/docs/sessions but when I run this code, I get error that "memcache is not defined".

../bin/server.php

PHP:

<?php
use Ratchet\Http\HttpServer;
use Ratchet\WebSocket\WsServer;
use Ratchet\Server\Ioserver;
use MyApp\Game;
use Ratchet\Session\SessionProvider;
use Symfony\Component\HttpFoundation\Session\Storage\Handler;

require_once dirname(__DIR__).'/vendor/autoload.php';

$ip = "127.0.0.1";

$memcache = new Memcache;
$memcache->connect($ip, 11211);

$session = new SessionProvider(
    new Game,
    new Handler\MemcacheSessionHandler($memcache)
);

$server = IoServer::factory(
    new HttpServer(
            new WsServer(
                $session//new Game()
            )
        ),
        8585
    );

$server->run();
?>

ERROR :

Fatal error: Class 'Memcache' not found in C:\xampp\htdocs\app\bin\server
.php on line 13
halfer
  • 19,824
  • 17
  • 99
  • 186
amin msh
  • 472
  • 5
  • 14

1 Answers1

1
  1. Execute php -i command and check if it shows Memcache extension (and don't confuse it with Memcached extension - they are different though their names are similar.
  2. If there isn't Memcache extension in the output of the previous command, then install Memcache extension to your PHP installation. How to do it - depends of your PHP installation and the system you are on. But usualy you can install PHP extension through PEAR utility like so: pecl install Memcache
SergeyLebedev
  • 3,673
  • 15
  • 29