Skip to content

Commit 0b0a1ba

Browse files
committed
Fixed #563 (Memcached connection issue)
1 parent e4b744e commit 0b0a1ba

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

src/phpFastCache/Drivers/Memcache/Driver.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,12 +163,21 @@ protected function driverConnect()
163163
}
164164

165165
if (!empty($server[ 'sasl_user' ]) && !empty($server[ 'sasl_password' ])) {
166-
$this->instance->setSaslAuthData($server[ 'sasl_user' ], $server[ 'sasl_password' ]);
166+
throw new phpFastCacheDriverException('Unlike Memcached, Memcache does not support SASL authentication');
167167
}
168168
} catch (\Exception $e) {
169169
$this->fallback = true;
170170
}
171171
}
172+
173+
/**
174+
* Since Memcached does not throw
175+
* any error if not connected ...
176+
*/
177+
if(!$this->instance->getServerStatus()){
178+
throw new phpFastCacheDriverException('Memcache seems to not be connected');
179+
}
180+
return true;
172181
}
173182

174183
/********************

src/phpFastCache/Drivers/Memcached/Driver.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,10 +159,21 @@ protected function driverConnect()
159159
if (!empty($server[ 'sasl_user' ]) && !empty($server[ 'sasl_password' ])) {
160160
$this->instance->setSaslAuthData($server[ 'sasl_user' ], $server[ 'sasl_password' ]);
161161
}
162+
162163
} catch (\Exception $e) {
163164
$this->fallback = true;
164165
}
165166
}
167+
168+
/**
169+
* Since Memcached does not throw
170+
* any error if not connected ...
171+
*/
172+
$version = $this->instance->getVersion();
173+
if(!$version || $this->instance->getResultCode() !== MemcachedSoftware::RES_SUCCESS){
174+
throw new phpFastCacheDriverException('Memcached seems to not be connected');
175+
}
176+
return true;
166177
}
167178

168179
/********************

0 commit comments

Comments
 (0)