/**
  * This function is used to find an existing storage object. It will return NULL if no storage object
  * with the given id is found.
  *
  * @param $id  The id of the storage object we are looking for. A id consists of lowercase
  *             alphanumeric characters.
  * @return The corresponding MemcacheStorage object if the data is found or NULL if it isn't found.
  */
 public static function find($id)
 {
     assert(self::isValidID($id));
     $serializedData = SimpleSAML_Memcache::get($id);
     if ($serializedData === NULL) {
         return NULL;
     }
     $data = unserialize($serializedData);
     if (!$data instanceof self) {
         SimpleSAML_Logger::warning('Retrieved key from memcache did not contain a MemcacheStore object.');
         return NULL;
     }
     return $data;
 }
/**
 * Sanity check for memcache servers.
 *
 * This function verifies that all memcache servers work.
 *
 * @param array &$hookinfo  hookinfo
 */
function memcacheMonitor_hook_sanitycheck(&$hookinfo)
{
    assert('is_array($hookinfo)');
    assert('array_key_exists("errors", $hookinfo)');
    assert('array_key_exists("info", $hookinfo)');
    try {
        $servers = SimpleSAML_Memcache::getRawStats();
    } catch (Exception $e) {
        $hookinfo['errors'][] = '[memcacheMonitor] Error parsing memcache configuration: ' . $e->getMessage();
        return;
    }
    $allOK = TRUE;
    foreach ($servers as $group) {
        foreach ($group as $server => $status) {
            if ($status === FALSE) {
                $hookinfo['errors'][] = '[memcacheMonitor] No response from server: ' . $server;
                $allOK = FALSE;
            }
        }
    }
    if ($allOK) {
        $hookinfo['info'][] = '[memcacheMonitor] All servers responding.';
    }
}
Example #3
0
 /**
  * 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.
  *
  * @return Memcache[] Array with Memcache objects.
  *
  * @throws Exception If the servers configuration is invalid.
  */
 private static function getMemcacheServers()
 {
     // check if we have loaded the servers already
     if (self::$serverGroups != null) {
         return self::$serverGroups;
     }
     // initialize the servers-array
     self::$serverGroups = array();
     // load the configuration
     $config = SimpleSAML_Configuration::getInstance();
     $groups = $config->getArray('memcache_store.servers');
     // iterate over all the groups in the 'memcache_store.servers' configuration option
     foreach ($groups as $index => $group) {
         // make sure that the group doesn't have an index. An index would be a sign of invalid configuration
         if (!is_int($index)) {
             throw new Exception("Invalid index on element in the 'memcache_store.servers'" . ' configuration option. Perhaps you have forgotten to add an array(...)' . ' around one of the server groups? The invalid index was: ' . $index);
         }
         /*
          * Make sure that the group is an array. Each group is an array of servers. Each server is
          * an array of name => value pairs for that server.
          */
         if (!is_array($group)) {
             throw new Exception("Invalid value for the server with index " . $index . ". Remeber that the 'memcache_store.servers' configuration option" . ' contains an array of arrays of arrays.');
         }
         // parse and add this group to the server group list
         self::$serverGroups[] = self::loadMemcacheServerGroup($group);
     }
     return self::$serverGroups;
 }
 /**
  * @group integration
  * @group memcached
  */
 public function testGetNonObject()
 {
     $store = new \sspmod_oauth2server_Store_MemCacheStore(array('prefix' => 'dummy'));
     $object = 'blah';
     \SimpleSAML_Memcache::set('dummy.blah', $object, time() + 1000);
     $object = $store->getObject('blah');
     $this->assertNull($object);
 }
 /**
  * Delete a value from the datastore.
  *
  * @param string $type  The datatype.
  * @param string $key  The key.
  */
 public function delete($type, $key)
 {
     assert('is_string($type)');
     assert('is_string($key)');
     SimpleSAML_Memcache::delete('simpleSAMLphp.' . $type . '.' . $key);
 }
 /**
  * @param $ticketId string
  */
 public function deleteTicket($ticketId)
 {
     $scopedTicketId = $this->scopeTicketId($ticketId);
     SimpleSAML_Memcache::delete($scopedTicketId);
 }
            continue;
        }
        $items = $state['curr_items'];
        echo "Server " . $server . " has " . $items . " items.\n";
        $serverKeys = getServerKeys($server);
        $keys = array_merge($keys, $serverKeys);
    }
}
echo "Total number of keys: " . count($keys) . "\n";
$keys = array_unique($keys);
echo "Total number of unique keys: " . count($keys) . "\n";
echo "Starting synchronization.\n";
$skipped = 0;
$sync = 0;
foreach ($keys as $key) {
    $res = SimpleSAML_Memcache::get($key);
    if ($res === NULL) {
        $skipped += 1;
    } else {
        $sync += 1;
    }
}
echo "Synchronization done.\n";
echo $sync . " keys in sync.\n";
if ($skipped > 0) {
    echo $skipped . " keys skipped.\n";
    echo "Keys are skipped because they are either expired, or are of a type unknown\n";
    echo "to simpleSAMLphp.\n";
}
if ($warnServerDown > 0) {
    echo "WARNING: " . $warnServerDown . " server(s) down. Not all servers are synchronized.\n";
 public function removeObject($identity)
 {
     $scopedId = $this->scopeId($identity);
     SimpleSAML_Memcache::delete($scopedId);
 }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    return $output;
}
$config = SimpleSAML_Configuration::getInstance();
// Make sure that the user has admin access rights
SimpleSAML\Utils\Auth::requireAdmin();
$formats = array('bytes' => 'humanreadable', 'bytes_read' => 'humanreadable', 'bytes_written' => 'humanreadable', 'limit_maxbytes' => 'humanreadable', 'time' => 'tdate', 'uptime' => 'hours');
$statsraw = SimpleSAML_Memcache::getStats();
$stats = $statsraw;
foreach ($stats as $key => &$entry) {
    if (array_key_exists($key, $formats)) {
        $func = $formats[$key];
        foreach ($entry as $k => $val) {
            $entry[$k] = $func($val);
        }
    }
}
$t = new SimpleSAML_XHTML_Template($config, 'memcacheMonitor:memcachestat.tpl.php');
$rowTitles = array('accepting_conns' => $t->noop('{memcacheMonitor:memcachestat:accepting_conns}'), 'auth_cmds' => $t->noop('{memcacheMonitor:memcachestat:auth_cmds}'), 'auth_errors' => $t->noop('{memcacheMonitor:memcachestat:auth_errors}'), 'bytes' => $t->noop('{memcacheMonitor:memcachestat:bytes}'), 'bytes_read' => $t->noop('{memcacheMonitor:memcachestat:bytes_read}'), 'bytes_written' => $t->noop('{memcacheMonitor:memcachestat:bytes_written}'), 'cas_badval' => $t->noop('{memcacheMonitor:memcachestat:cas_badval}'), 'cas_hits' => $t->noop('{memcacheMonitor:memcachestat:cas_hits}'), 'cas_misses' => $t->noop('{memcacheMonitor:memcachestat:cas_misses}'), 'cmd_get' => $t->noop('{memcacheMonitor:memcachestat:cmd_get}'), 'cmd_set' => $t->noop('{memcacheMonitor:memcachestat:cmd_set}'), 'connection_structures' => $t->noop('{memcacheMonitor:memcachestat:connection_structures}'), 'conn_yields' => $t->noop('{memcacheMonitor:memcachestat:conn_yields}'), 'curr_connections' => $t->noop('{memcacheMonitor:memcachestat:curr_connections}'), 'curr_items' => $t->noop('{memcacheMonitor:memcachestat:curr_items}'), 'decr_hits' => $t->noop('{memcacheMonitor:memcachestat:decr_hits}'), 'decr_misses' => $t->noop('{memcacheMonitor:memcachestat:decr_misses}'), 'delete_hits' => $t->noop('{memcacheMonitor:memcachestat:delete_hits}'), 'delete_misses' => $t->noop('{memcacheMonitor:memcachestat:delete_misses}'), 'evictions' => $t->noop('{memcacheMonitor:memcachestat:evictions}'), 'get_hits' => $t->noop('{memcacheMonitor:memcachestat:get_hits}'), 'get_misses' => $t->noop('{memcacheMonitor:memcachestat:get_misses}'), 'incr_hits' => $t->noop('{memcacheMonitor:memcachestat:incr_hits}'), 'incr_misses' => $t->noop('{memcacheMonitor:memcachestat:incr_misses}'), 'limit_maxbytes' => $t->noop('{memcacheMonitor:memcachestat:limit_maxbytes}'), 'listen_disabled_num' => $t->noop('{memcacheMonitor:memcachestat:listen_disabled_num}'), 'pid' => $t->noop('{memcacheMonitor:memcachestat:pid}'), 'pointer_size' => $t->noop('{memcacheMonitor:memcachestat:pointer_size}'), 'rusage_system' => $t->noop('{memcacheMonitor:memcachestat:rusage_system}'), 'rusage_user' => $t->noop('{memcacheMonitor:memcachestat:rusage_user}'), 'threads' => $t->noop('{memcacheMonitor:memcachestat:threads}'), 'time' => $t->noop('{memcacheMonitor:memcachestat:time}'), 'total_connections' => $t->noop('{memcacheMonitor:memcachestat:total_connections}'), 'total_items' => $t->noop('{memcacheMonitor:memcachestat:total_items}'), 'uptime' => $t->noop('{memcacheMonitor:memcachestat:uptime}'), 'version' => $t->noop('{memcacheMonitor:memcachestat:version}'));
$t->data['title'] = 'Memcache stats';
$t->data['rowtitles'] = $rowTitles;
$t->data['table'] = $stats;
$t->data['statsraw'] = $statsraw;
Example #10
0
 protected static function cacheSET($calID, $freebusy)
 {
     return SimpleSAML_Memcache::set('calendar-' . $calID, json_encode($freebusy));
 }
Example #11
0
 /**
  * This function stores this storage object to the memcache servers.
  */
 public function save()
 {
     /* Write to the memcache servers. */
     SimpleSAML_Memcache::set($this->id, serialize($this));
 }