все У меня возникла проблема при попытке использовать memcache с php Я hava успешно устанавливаю расширение php и memcached. Я пишу memtest.php, чтобы проверить его, и это успех. Вот тест.php Класс Memcache не найден
<?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;
}
}
И я использую PHP автозагрузку в init.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;
}
}
И на этот раз он показал мне
загрузчика классов не удалось загрузить класс Memcache
abviously, The Memcache класс не может быть найден, но почему тест PHP успех?
Желаю, чтобы кто-то мог мне помочь, потому что я действительно новичок в php.
Thks для ответа, но я уже расширения, и я думаю, что он был установлен правильно, потому что я написал скрипт memtest.php, и все идет хорошо, и код, который я написал в моем вопросе. –