|
static | get ($key) |
| Find data stored with a given key. More...
|
|
static | set ($key, $value, $expire=null) |
| Save a key-value pair to the memcache servers. More...
|
|
static | delete ($key) |
| Delete a key-value pair from the memcache servers. More...
|
|
static | getStats () |
| This function retrieves statistics about all memcache server groups. More...
|
|
static | getRawStats () |
| Retrieve statistics directly in the form returned by getExtendedStats, for all server groups. More...
|
|
|
static | addMemcacheServer ($memcache, $server) |
| This function adds a server from the 'memcache_store.servers' configuration option to a Memcache object. More...
|
|
static | loadMemcacheServerGroup (array $group) |
| This function takes in a list of servers belonging to a group and creates a Memcache object from the servers in the group. More...
|
|
static | getMemcacheServers () |
| This function gets a list of all configured memcache servers. More...
|
|
static | getExpireTime () |
| This is a helper-function which returns the expire value of data we should store to the memcache servers. More...
|
|
Definition at line 20 of file Memcache.php.
◆ addMemcacheServer()
static SimpleSAML_Memcache::addMemcacheServer |
( |
|
$memcache, |
|
|
|
$server |
|
) |
| |
|
staticprivate |
This function adds a server from the 'memcache_store.servers' configuration option to a Memcache object.
The server parameter is an array with the following keys:
- hostname Hostname or ip address to the memcache server.
- port (optional) port number the memcache server is running on. This defaults to memcache.default_port if no value is given. The default value of memcache.default_port is 11211.
- weight (optional) The weight of this server in the load balancing cluster.
- timeout (optional) The timeout for contacting this server, in seconds. The default value is 3 seconds.
- Parameters
-
Memcache | $memcache | The Memcache object we should add this server to. |
array | $server | An associative array with the configuration options for the server to add. |
- Exceptions
-
Exception | If any configuration option for the server is invalid. |
Definition at line 215 of file Memcache.php.
References $memcache, and $server.
218 if (!array_key_exists(
'hostname',
$server)) {
220 "hostname setting missing from server in the 'memcache_store.servers' configuration option." 224 $hostname =
$server[
'hostname'];
227 if (!is_string($hostname)) {
229 "Invalid hostname for server in the 'memcache_store.servers' configuration option. The hostname is".
230 ' supposed to be a string.' 236 if (strpos($hostname,
'unix:///') === 0) {
244 } elseif (array_key_exists(
'port',
$server)) {
247 if (($port <= 0) || ($port > 65535)) {
249 "Invalid port for server in the 'memcache_store.servers' configuration option. The port number".
250 ' is supposed to be an integer between 0 and 65535.' 255 $port = (int) ini_get(
'memcache.default_port');
256 if ($port <= 0 || $port > 65535) {
263 if (array_key_exists(
'weight',
$server)) {
265 $weight = (int)
$server[
'weight'];
268 "Invalid weight for server in the 'memcache_store.servers' configuration option. The weight is".
269 ' supposed to be a positive integer.' 278 if (array_key_exists(
'timeout',
$server)) {
280 $timeout = (int)
$server[
'timeout'];
283 "Invalid timeout for server in the 'memcache_store.servers' configuration option. The timeout is".
284 ' supposed to be a positive integer.' 293 if (self::$extension ===
'memcached') {
296 $memcache->addServer($hostname, $port,
true, $weight, $timeout, $timeout,
true);
foreach($authData as $name=> $values) $memcache
◆ delete()
static SimpleSAML_Memcache::delete |
( |
|
$key | ) |
|
|
static |
◆ get()
static SimpleSAML_Memcache::get |
( |
|
$key | ) |
|
|
static |
Find data stored with a given key.
- Parameters
-
string | $key | The key of the data. |
- Returns
- mixed The data stored with the given key, or null if no data matching the key was found.
Definition at line 46 of file Memcache.php.
References $info, $key, $server, SimpleSAML\Logger\debug(), and SimpleSAML\Logger\warning().
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);
◆ getExpireTime()
static SimpleSAML_Memcache::getExpireTime |
( |
| ) |
|
|
staticprivate |
This is a helper-function which returns the expire value of data we should store to the memcache servers.
The value is set depending on the configuration. If no value is set in the configuration, then we will use a default value of 0. 0 means that the item will never expire.
- Returns
- integer The value which should be passed in the set(...) calls to the memcache objects.
- Exceptions
-
Exception | If the option 'memcache_store.expires' has a negative value. |
Definition at line 416 of file Memcache.php.
References $config, $expire, SimpleSAML_Configuration\getInstance(), and time.
428 "The value of 'memcache_store.expires' in the configuration can't be a negative integer."
Add data(end) time
Method that wraps PHPs time in order to allow simulations with the workflow.
static getInstance($instancename='simplesaml')
Get a configuration file by its instance name.
◆ getMemcacheServers()
static SimpleSAML_Memcache::getMemcacheServers |
( |
| ) |
|
|
staticprivate |
This function gets a list of all configured memcache servers.
This list is initialized based on the content of 'memcache_store.servers' in the configuration.
- Returns
- Memcache[] Array with Memcache objects.
- Exceptions
-
Exception | If the servers configuration is invalid. |
Definition at line 357 of file Memcache.php.
References $config, $index, array, and SimpleSAML_Configuration\getInstance().
360 if (self::$serverGroups != null) {
361 return self::$serverGroups;
365 self::$serverGroups =
array();
371 $groups =
$config->getArray(
'memcache_store.servers');
374 foreach ($groups as
$index => $group) {
378 "Invalid index on element in the 'memcache_store.servers'".
379 ' configuration option. Perhaps you have forgotten to add an array(...)'.
380 ' around one of the server groups? The invalid index was: '.
$index 388 if (!is_array($group)) {
390 "Invalid value for the server with index ".
$index.
391 ". Remeber that the 'memcache_store.servers' configuration option".
392 ' contains an array of arrays of arrays.' 397 self::$serverGroups[] = self::loadMemcacheServerGroup($group);
400 return self::$serverGroups;
Create styles array
The data for the language used.
static getInstance($instancename='simplesaml')
Get a configuration file by its instance name.
◆ getRawStats()
static SimpleSAML_Memcache::getRawStats |
( |
| ) |
|
|
static |
Retrieve statistics directly in the form returned by getExtendedStats, for all server groups.
- Returns
- array An array with the extended stats output for each server group.
Definition at line 482 of file Memcache.php.
References $ret, $stats, and array.
Referenced by memcacheMonitor_hook_sanitycheck().
486 foreach (self::getMemcacheServers() as $sg) {
487 $stats = method_exists($sg,
'getExtendedStats') ? $sg->getExtendedStats() : $sg->getStats();
Create styles array
The data for the language used.
◆ getStats()
static SimpleSAML_Memcache::getStats |
( |
| ) |
|
|
static |
This function retrieves statistics about all memcache server groups.
- Returns
- array Array with the names of each stat and an array with the value for each server group.
- Exceptions
-
Exception | If memcache server status couldn't be retrieved. |
Definition at line 455 of file Memcache.php.
References $data, $ret, $server, $stats, array, and SimpleSAML\Utils\Arrays\transpose().
459 foreach (self::getMemcacheServers() as $sg) {
460 $stats = method_exists($sg,
'getExtendedStats') ? $sg->getExtendedStats() : $sg->getStats();
462 if (
$data ===
false) {
463 throw new Exception(
'Failed to get memcache server status.');
static transpose($array)
This function transposes a two-dimensional array, so that $a['k1']['k2'] becomes $a['k2']['k1'].
Create styles array
The data for the language used.
◆ loadMemcacheServerGroup()
static SimpleSAML_Memcache::loadMemcacheServerGroup |
( |
array |
$group | ) |
|
|
staticprivate |
This function takes in a list of servers belonging to a group and creates a Memcache object from the servers in the group.
- Parameters
-
array | $group | Array of servers which should be created as a group. |
- Returns
- Memcache A Memcache object of the servers in the group
- Exceptions
-
Exception | If the servers configuration is invalid. |
Definition at line 311 of file Memcache.php.
References $index, $memcache, and $server.
313 $class = class_exists(
'Memcache') ?
'Memcache' : (class_exists(
'Memcached') ?
'Memcached' : FALSE);
315 throw new Exception(
'Missing Memcached implementation. You must install either the Memcache or Memcached extension.');
317 self::$extension = strtolower($class);
327 "Invalid index on element in the 'memcache_store.servers' configuration option. Perhaps you".
328 ' have forgotten to add an array(...) around one of the server groups? The invalid index was: '.
336 'Invalid value for the server with index '.
$index.
337 '. Remeber that the \'memcache_store.servers\' configuration option'.
338 ' contains an array of arrays of arrays.' foreach($authData as $name=> $values) $memcache
◆ set()
static SimpleSAML_Memcache::set |
( |
|
$key, |
|
|
|
$value, |
|
|
|
$expire = null |
|
) |
| |
|
static |
Save a key-value pair to the memcache servers.
- Parameters
-
string | $key | The key of the data. |
mixed | $value | The value of the data. |
integer | null | $expire | The expiration timestamp of the data. |
Definition at line 149 of file Memcache.php.
References $key, $server, array, and SimpleSAML\Logger\debug().
Referenced by SimpleSAML\Store\Memcache\set().
153 'timestamp' => microtime(
true),
158 $expire = self::getExpireTime();
161 $savedInfoSerialized = serialize($savedInfo);
164 foreach (self::getMemcacheServers() as
$server) {
165 if (self::$extension ===
'memcached') {
169 $server->set(
$key, $savedInfoSerialized, 0,
$expire);
Create styles array
The data for the language used.
◆ $extension
SimpleSAML_Memcache::$extension = '' |
|
staticprivate |
◆ $serverGroups
SimpleSAML_Memcache::$serverGroups = null |
|
staticprivate |
The documentation for this class was generated from the following file:
- libs/composer/vendor/simplesamlphp/simplesamlphp/lib/SimpleSAML/Memcache.php