* // Create a new localhost Memcached connection instance. * $memcache = Memcached::connect(array('host' => '127.0.0.1', 'port' => 11211)); * * * @param array $servers * @return Memcache */ public static function connect($servers) { $memcache = new \Memcache; foreach ($servers as $server) { $memcache->addServer($server['host'], $server['port'], true, $server['weight']); } if ($memcache->getVersion() === false) { throw new \RuntimeException('Could not establish memcached connection.'); } return $memcache; } /** * Dynamically pass all other method calls to the Memcache instance. * * * // Get an item from the Memcache instance * $name = Memcached::get('name'); * * // Store data on the Memcache server * Memcached::set('name', 'Taylor'); * */ public static function __callStatic($method, $parameters) { return call_user_func_array(array(static::instance(), $method), $parameters); } }