From ae42790c2e016a25aadca30033d53ab567890023 Mon Sep 17 00:00:00 2001 From: Adam Malone <adam@adammalone.net> Date: Tue, 1 Aug 2017 10:40:09 +1000 Subject: [PATCH] Adds further support for php-memcached. --- bin/memcacheSync.php | 25 +++++++++++++------------ docs/simplesamlphp-artifact-idp.md | 5 ++++- lib/SimpleSAML/AuthMemCookie.php | 9 ++++++++- modules/core/www/frontpage_config.php | 6 +++++- 4 files changed, 30 insertions(+), 15 deletions(-) diff --git a/bin/memcacheSync.php b/bin/memcacheSync.php index 50da31774..3aa432e8f 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 4614f787d..41108ec67 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 ef8a0773f..33944677e 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/modules/core/www/frontpage_config.php b/modules/core/www/frontpage_config.php index 7f92a6ef3..af145e255 100644 --- a/modules/core/www/frontpage_config.php +++ b/modules/core/www/frontpage_config.php @@ -111,7 +111,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)'); @@ -129,6 +128,11 @@ foreach ($functionchecks AS $func => $descr) { $funcmatrix[] = array('descr' => $descr[1], 'required' => $descr[0], 'enabled' => function_exists($func)); } +$funcmatrix[] = array( + 'required' => 'optional', + 'descr' => 'Memcache or Memcached Extension (required if a Memcached backend is used)', + 'enabled' => class_exists('Memcache') || class_exists('Memcached'), +); /* Some basic configuration checks */ -- GitLab