Skip to content
Snippets Groups Projects
Commit 64bf11b6 authored by Thijs Kinkhorst's avatar Thijs Kinkhorst Committed by GitHub
Browse files

Merge pull request #395 from bradjones1/memcached

Memcached extension support
parents 64b23a4b 592e596b
No related branches found
No related tags found
No related merge requests found
......@@ -3,18 +3,19 @@
// Check that the memcache library is enabled
if (!class_exists('Memcache')) {
echo("Error: the memcache library appears to be unavailable.\n");
echo("\n");
echo("This is most likely because PHP doesn't load it for the command line\n");
echo("version. You probably need to enable it somehow.\n");
echo("\n");
if(is_executable('/usr/sbin/phpenmod')) {
echo("It is possible that running the following command as root will fix it:\n");
echo(" phpenmod -s cli memcache\n");
}
exit(1);
if(!class_exists('Memcache') && !class_exists('Memcached')) {
echo("Error: the memcache and memcached libraries appear to be unavailable.\n");
echo("\n");
echo("This is most likely because PHP doesn't load it for the command line\n");
echo("version. You probably need to enable one of them somehow.\n");
echo("\n");
if(is_dir('/etc/php5/cli/conf.d')) {
echo("It is possible that running one of the following commands as root will fix it:\n");
echo(" echo 'extension=memcache.so' >/etc/php5/cli/conf.d/memcache.ini\n");
echo(" echo 'extension=memcached.so' >/etc/php5/cli/conf.d/memcached.ini\n");
}
exit(1);
}
// This is the base directory of the SimpleSAMLphp installation
......
......@@ -14,9 +14,12 @@ Memcache
To enable memcache, you must first install and configure memcache on the server hosting your IdP.
You need both a memcache server and a the PHP memcache client.
How this is done depends on the distribution.
If you are running Debian Lenny, you can install both by running:
If you are running Debian Lenny, you can install both by running one of the following:
aptitude install memcached php5-memcache
aptitude install memcached php5-memcached
The memcached extension should be used for PHP 7.
*Note*: For security, you must make sure that the memcache server is inaccessible to other hosts.
The default configuration on Debian Lenny is for the memcache server to be accessible to only the local host.
......
......@@ -110,13 +110,20 @@ class SimpleSAML_AuthMemCookie
* This function creates and initializes a Memcache object from our configuration.
*
* @return Memcache A Memcache object initialized from our configuration.
* @throws Exception If the servers configuration is invalid.
*/
public function getMemcache()
{
$memcacheHost = $this->amcConfig->getString('memcache.host', '127.0.0.1');
$memcachePort = $this->amcConfig->getInteger('memcache.port', 11211);
$memcache = new Memcache;
$class = class_exists('Memcache') ? 'Memcache' : (class_exists('Memcached') ? 'Memcached' : FALSE);
if (!$class) {
throw new Exception('Missing Memcached implementation. You must install either the Memcache or Memcached extension.');
}
// Create the Memcache(d) object.
$memcache = new $class();
foreach (explode(',', $memcacheHost) as $memcacheHost) {
$memcache->addServer($memcacheHost, $memcachePort);
......
......@@ -28,6 +28,14 @@ class SimpleSAML_Memcache
private static $serverGroups = null;
/**
* The flavor of memcache PHP extension we are using.
*
* @var string
*/
private static $extension = '';
/**
* Find data stored with a given key.
*
......@@ -154,7 +162,12 @@ class SimpleSAML_Memcache
// store this object to all groups of memcache servers
foreach (self::getMemcacheServers() as $server) {
$server->set($key, $savedInfoSerialized, 0, $expire);
if (self::$extension === 'memcached') {
$server->set($key, $savedInfoSerialized, $expire);
}
else {
$server->set($key, $savedInfoSerialized, 0, $expire);
}
}
}
......@@ -277,7 +290,11 @@ class SimpleSAML_Memcache
}
// add this server to the Memcache object
$memcache->addServer($hostname, $port, true, $weight, $timeout, $timeout, true);
if (self::$extension === 'memcached') {
$memcache->addServer($hostname, $port);
} else {
$memcache->addServer($hostname, $port, true, $weight, $timeout, $timeout, true);
}
}
......@@ -293,12 +310,14 @@ class SimpleSAML_Memcache
*/
private static function loadMemcacheServerGroup(array $group)
{
if (!class_exists('Memcache')) {
throw new Exception('Missing Memcache class. Is the memcache extension installed?');
$class = class_exists('Memcache') ? 'Memcache' : (class_exists('Memcached') ? 'Memcached' : FALSE);
if (!$class) {
throw new Exception('Missing Memcached implementation. You must install either the Memcache or Memcached extension.');
}
self::$extension = strtolower($class);
// create the Memcache object
$memcache = new Memcache();
$memcache = new $class();
// iterate over all the servers in the group and add them to the Memcache object
foreach ($group as $index => $server) {
......
......@@ -112,7 +112,6 @@ $functionchecks = array(
'mcrypt_module_open'=> array('optional', 'MCrypt (required if digital signatures or encryption are used)'),
'session_start' => array('optional', 'Session Extension (required if PHP sessions are used)'),
'pdo_drivers' => array('optional', 'PDO Extension (required if a database backend is used)'),
'memcache_debug' => array('optional', 'Memcache Extension (required if a Memcached backend is used)'),
);
if (SimpleSAML\Module::isModuleEnabled('ldap')) {
$functionchecks['ldap_bind'] = array('optional', 'LDAP Extension (required if an LDAP backend is used)');
......@@ -136,6 +135,11 @@ $funcmatrix[] = array(
'enabled' => class_exists('\Predis\Client'),
);
$funcmatrix[] = array(
'descr' => 'Memcache or Memcached Extension (required if a Memcached backend is used)',
'enabled' => class_exists('Memcache') || class_exists('Memcached'),
);
/* Some basic configuration checks */
if($config->getString('technicalcontact_email', 'na@example.org') === 'na@example.org') {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment