diff --git a/bin/memcacheSync.php b/bin/memcacheSync.php index 50da31774711a51c191cc27628d63ea02690de36..3aa432e8fef295d9019b10cbad52caf65cc98833 100755 --- a/bin/memcacheSync.php +++ b/bin/memcacheSync.php @@ -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 diff --git a/docs/simplesamlphp-artifact-idp.md b/docs/simplesamlphp-artifact-idp.md index 4614f787d01d283fcedd97c8dd52e155e1f074dd..41108ec672c2e76b6a651b4879a1daebb7bd334f 100644 --- a/docs/simplesamlphp-artifact-idp.md +++ b/docs/simplesamlphp-artifact-idp.md @@ -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. diff --git a/lib/SimpleSAML/AuthMemCookie.php b/lib/SimpleSAML/AuthMemCookie.php index ef8a0773fbd98fe430a9afd8ea02b89d66cb4ab0..33944677e48399d63c2bbc9863e5dd9e42fea77a 100644 --- a/lib/SimpleSAML/AuthMemCookie.php +++ b/lib/SimpleSAML/AuthMemCookie.php @@ -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); diff --git a/lib/SimpleSAML/Memcache.php b/lib/SimpleSAML/Memcache.php index 199833d9f5b6debbb71e687b60a858a497e2fce4..a901465d293dc6e11b4e77137062082442622361 100644 --- a/lib/SimpleSAML/Memcache.php +++ b/lib/SimpleSAML/Memcache.php @@ -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) { diff --git a/modules/core/www/frontpage_config.php b/modules/core/www/frontpage_config.php index ec904981f90b83ede7e66f5501e3a64e379fc6bf..f501d077b7b8edbc8a299add44cdb89105ba1982 100644 --- a/modules/core/www/frontpage_config.php +++ b/modules/core/www/frontpage_config.php @@ -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') {