avoid PHP Fatal Error when memcache PHP modules are not available

This commit is contained in:
Laurent Laville 2021-04-19 17:24:11 +02:00
parent 46f5c48ba0
commit f6c273d6c4

View File

@ -37,6 +37,11 @@ class Memcd extends BaseClass implements BaseInterface
{
parent::__construct($hostname, $data);
// Faster check if memcached is not loaded
if (!$this->isAvailable()) {
return;
}
if (class_exists('Memcached')) {
$memcd = new \Memcached('_devilbox');
$list = $memcd->getServerList();
@ -274,4 +279,14 @@ class Memcd extends BaseClass implements BaseInterface
}
return $this->_version;
}
public function isAvailable()
{
if (extension_loaded('memcached')) {
return parent::isAvailable();
}
// when php module 'memcached' not available or just disable by configuration (see .env PHP_MODULES_DISABLE)
return false;
}
}