46 public static function get(
$key)
57 foreach (self::getMemcacheServers() as
$server) {
58 $serializedInfo = $server->get(
$key);
59 if ($serializedInfo ===
false) {
62 $up = $server->getstats();
71 $info = unserialize($serializedInfo);
78 if (!is_array(
$info)) {
80 'Retrieved invalid data from a memcache server. Data was not an array.' 84 if (!array_key_exists(
'timestamp',
$info)) {
86 'Retrieved invalid data from a memcache server. Missing timestamp.' 90 if (!array_key_exists(
'data',
$info)) {
92 'Retrieved invalid data from a memcache server. Missing data.' 97 if ($latestInfo === null) {
99 $latestInfo = $serializedInfo;
100 $latestTime =
$info[
'timestamp'];
101 $latestData =
$info[
'data'];
105 if (
$info[
'timestamp'] === $latestTime && $serializedInfo === $latestInfo) {
114 if ($latestTime <
$info[
'timestamp']) {
115 $latestInfo = $serializedInfo;
116 $latestTime =
$info[
'timestamp'];
117 $latestData =
$info[
'data'];
121 if ($latestData === null) {
135 self::set(
$key, $latestData);
153 'timestamp' => microtime(
true),
157 if ($expire === null) {
158 $expire = self::getExpireTime();
161 $savedInfoSerialized = serialize($savedInfo);
164 foreach (self::getMemcacheServers() as
$server) {
165 if (self::$extension ===
'memcached') {
166 $server->set(
$key, $savedInfoSerialized, $expire);
168 $server->set(
$key, $savedInfoSerialized, 0, $expire);
179 public static function delete(
$key)
181 assert(is_string(
$key));
185 foreach (self::getMemcacheServers() as
$server) {
186 $server->delete(
$key);
217 if (!array_key_exists(
'hostname',
$server)) {
219 "hostname setting missing from server in the 'memcache_store.servers' configuration option." 223 $hostname =
$server[
'hostname'];
226 if (!is_string($hostname)) {
228 "Invalid hostname for server in the 'memcache_store.servers' configuration option. The hostname is".
229 ' supposed to be a string.' 235 if (strpos($hostname,
'unix:///') === 0) {
243 } elseif (array_key_exists(
'port',
$server)) {
246 if (($port <= 0) || ($port > 65535)) {
248 "Invalid port for server in the 'memcache_store.servers' configuration option. The port number".
249 ' is supposed to be an integer between 0 and 65535.' 254 $port = (int) ini_get(
'memcache.default_port');
255 if ($port <= 0 || $port > 65535) {
262 if (array_key_exists(
'weight',
$server)) {
264 $weight = (int)
$server[
'weight'];
267 "Invalid weight for server in the 'memcache_store.servers' configuration option. The weight is".
268 ' supposed to be a positive integer.' 277 if (array_key_exists(
'timeout',
$server)) {
279 $timeout = (int)
$server[
'timeout'];
282 "Invalid timeout for server in the 'memcache_store.servers' configuration option. The timeout is".
283 ' supposed to be a positive integer.' 292 if (self::$extension ===
'memcached') {
295 $memcache->addServer($hostname, $port,
true, $weight, $timeout, $timeout,
true);
312 $class = class_exists(
'Memcache') ?
'Memcache' : (class_exists(
'Memcached') ?
'Memcached' :
false);
314 throw new Exception(
'Missing Memcached implementation. You must install either the Memcache or Memcached extension.');
316 self::$extension = strtolower($class);
326 "Invalid index on element in the 'memcache_store.servers' configuration option. Perhaps you".
327 ' have forgotten to add an array(...) around one of the server groups? The invalid index was: '.
335 'Invalid value for the server with index '.
$index.
336 '. Remeber that the \'memcache_store.servers\' configuration option'.
337 ' contains an array of arrays of arrays.' 359 if (self::$serverGroups != null) {
360 return self::$serverGroups;
364 self::$serverGroups = array();
370 $groups =
$config->getArray(
'memcache_store.servers');
373 foreach ($groups as
$index => $group) {
377 "Invalid index on element in the 'memcache_store.servers'".
378 ' configuration option. Perhaps you have forgotten to add an array(...)'.
379 ' around one of the server groups? The invalid index was: '.
$index 387 if (!is_array($group)) {
389 "Invalid value for the server with index ".
$index.
390 ". Remeber that the 'memcache_store.servers' configuration option".
391 ' contains an array of arrays of arrays.' 396 self::$serverGroups[] = self::loadMemcacheServerGroup($group);
399 return self::$serverGroups;
422 $expire =
$config->getInteger(
'memcache_store.expires', 0);
427 "The value of 'memcache_store.expires' in the configuration can't be a negative integer." 441 $expireTime = time() +
$expire;
458 foreach (self::getMemcacheServers() as $sg) {
459 $stats = method_exists($sg,
'getExtendedStats') ? $sg->getExtendedStats() : $sg->getStats();
461 if (
$data ===
false) {
462 throw new Exception(
'Failed to get memcache server status.');
485 foreach (self::getMemcacheServers() as $sg) {
486 $stats = method_exists($sg,
'getExtendedStats') ? $sg->getExtendedStats() : $sg->getStats();
foreach($authData as $name=> $values) $memcache
static transpose($array)
This function transposes a two-dimensional array, so that $a['k1']['k2'] becomes $a['k2']['k1'].
static getMemcacheServers()
This function gets a list of all configured memcache servers.
static getRawStats()
Retrieve statistics directly in the form returned by getExtendedStats, for all server groups...
static getExpireTime()
This is a helper-function which returns the expire value of data we should store to the memcache serv...
static loadMemcacheServerGroup(array $group)
This function takes in a list of servers belonging to a group and creates a Memcache object from the ...
static addMemcacheServer($memcache, $server)
This function adds a server from the 'memcache_store.servers' configuration option to a Memcache obje...
static getInstance($instancename='simplesaml')
Get a configuration file by its instance name.
static getStats()
This function retrieves statistics about all memcache server groups.