Search code examples
phpratchet

PHP Ratchet: Class Memcache not found


I am following Ratchet's tutorials. For SessionProvider page, the code is like this:

<?php
// Your shell script
use Ratchet\Session\SessionProvider;
use Symfony\Component\HttpFoundation\Session\Storage\Handler;
use Ratchet\App;

$memcache = new Memcache; // Class not found on line 7
$memcache->connect('localhost', 11211);

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

$server = new App('localhost');
$server->route('/sessDemo', $session);
$server->run();

PHP throws a fatal error when I run the script in the command-line:

Class Memcache not found in on line 7

This code is placed in bin\chat-server.php

Wierd Stuff

The class is not available only for chat-server.php script.


Solution

  • There are two distinct PHP extensions for the service memcached:

    • memcache
    • memcached <-- note the d

    Looks like you have installed the latter one, while you need the first one for your application.

    You can find the right extension for Windows here