Home » Php » PHP Ratchet: Class Memcache not found

PHP Ratchet: Class Memcache not found

Posted by: admin July 12, 2020 Leave a comment


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

// 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);

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.

How to&Answers:

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