sorry, the right $config['memcached'] variable is $config['memcached']=array(array('host'=>'localhost', port=11211, persistent=1,weight=1)); 2011/6/28 xucheng <xucheng@xxxxxxxxxxx>: > 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 >