php 找不到内存缓存 class

php Memcache class can not be found

全部 尝试将 memcache 与 php 一起使用时出现问题 我已成功安装 php 和 memcached 扩展。 我写了一个 memtest.php 来测试它,它成功了。这是测试。

<?php
$memcache = new Memcache;  
$memcache->connect('xxxxxx', 11211) or die ("Could not connect");
$memcache->set('key', 'test'); 
$get_value = $memcache->get('key'); 
echo $get_value;
?>

回显测试

但是当我在我的 php 网络服务器中使用它时,我失败了。 这是我的代码: 我写了一个memcacheTool.php

<?php
/**
 * memcache operate tool
 *
 * @author      wanghao
 * @date        2015-12-25  
 */
class memcacheTool {

    //var $memcache;
    //static $memcacheD = new Nemcached;

    private $cacheServer = URL_OF_MEMCACHED;
    private $cachePort = 11211;
    private $memcache;
    private static $_instance;

    private function __construct()
    {
        if (class_exists("Memcache"))
        {
            $this -> memcache = new Memcache();
        }

        $res = $this -> memcache -> connect($cacheServer, $cachePort);

        if( false == $res)
        {
            $this -> memcache = null;
        }
    }

    public static function getInstance()
    {
        if (is_null( self::$_instance))
        {
            self::$_instance = new self();
        }
        return self::$_instance;
    }

    /**
     * set operation
     *
     * @param string    $key        
     * @param string    $value  
     */
    static function set($key, $value)
    {
        //error_log("memcache: set ".$key"value ".$value);
        if ( !trim($key) ) 
        {
            return false;
        }
        $memcache -> add($key,$value,MEMCACHE_COMPRESSED,0);

    }
    /**
      * get operation
      *
      * @param string   $key
      */
    static function get($key)
    {

        if ( !trim($key) ) {
            return null;
        }

        if (is_null($memcache -> get($key))){
            return null;
        } 
        $memValue = $memcache -> get($key);
        return $memValue;
    }

}

我在 init.php

中使用 php 自动加载
function __autoload($object)
{
    require("". $object . ".php");

    if ( !class_exists($object) )
    {
        error_log("<IMPORTANT>Class loader failed to load class " . $object);
        include_once("app/http.php");
        include_once("app/poster.php");
        include_once("app/handle.php");
        include_once("app/loader.php");
        include_once("app/casserver.php");
        return;
    }

}

显示Memcache.php没有找到,所以修改为

function __autoload($object)
{
    if ($object != "Memcache")
    {
        require("". $object . ".php");
    }
    if ( !class_exists($object) )
    {
        error_log("<IMPORTANT>Class loader failed to load class " . $object);
        include_once("app/http.php");
        include_once("app/poster.php");
        include_once("app/handle.php");
        include_once("app/loader.php");
        include_once("app/casserver.php");
        return;
    }

}

这次它让我看到了

Class loader failed to load class Memcache

明明找不到Memcacheclass,但是为什么测试php就成功了?

我希望有人能帮助我,因为我真的是 php 的新手。

需要先安装memcache扩展才能使用php

的memcache功能

请参考 PHP Memcached Installation