help for memcached Segmentation fault
| From: | xucheng | Date: | Tue, 28 Jun 2011 02:53:13 +0000 |
| Subject: | help for memcached Segmentation fault | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-313769@lists.php.net to get a copy of this message | ||
Hi all,
I wrap pecl-memcache into a class used as a sigleton class .
the code is :
==================================================code===================================================================================
class Mem{
private static $_instance = null ;//singlton object instance
private function __construct(){
global $config ;
$servers = $config['memcached'] ;
$mem = new Memcache ;
foreach($servers as $server){
$mem->addServer($server['host'],
$server['port'], intval($server['persistent']) > 0 ? 1 : 0,
intval($server['weight']) > 0 ? intval($server['weight']) : 1 ) ;
}
return $mem ;
}
private static function getInstance(){
if(self::$_instance === null || !(
self::$_instance instanceof Mem ) ){
self::$_instance = new Mem() ;
}
return true ;
}
public static function get($key){
self::getInstance() ;
return self::$_instance->get(md5(strtolower($key))) ;
}
public static function set($key, $value, $ttl=0){
self::getInstance() ;
$compress = (is_bool($value) || is_int($value)
|| is_float($value)) ? false : MEMCACHE_COMPRESSED ;
return
self::$_instance->set(md5(strtolower($key)), $value, $compress, $ttl)
;
}
public static function rm($key){
self::getInstance() ;
return
self::$_instance->delete(md5(strtolower($key)),0) ;
}
}
===============================================================code==========================================================
and $config['memcached'] is an array contains info about the server .
$config['memcached'] = array('host'=>'localhost', port=11211,
persistent=1,weight=1) ;
when i run this , i got "Segmentation fault" ! I cannot figure out
what's the problem . any commet appreciate .
and i used memcached 1.4.5 , and libevent-1.4.13-1
php 5.2.16