Skip to content

Commit b14b0e1

Browse files
[Cache] Handle unserialization failures for Memcached
1 parent 34d5f9e commit b14b0e1

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/Symfony/Component/Cache/Traits/MemcachedTrait.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ trait MemcachedTrait
2626
'persistent_id' => null,
2727
'username' => null,
2828
'password' => null,
29+
'serializer' => 'php',
2930
);
3031

3132
private $client;
@@ -186,15 +187,22 @@ public static function createConnection($servers, array $options = array())
186187
*/
187188
protected function doSave(array $values, $lifetime)
188189
{
189-
return $this->checkResultCode($this->client->setMulti($values, $lifetime));
190+
return $this->checkResultCode($this->client->setMulti($serialized, $lifetime));
190191
}
191192

192193
/**
193194
* {@inheritdoc}
194195
*/
195196
protected function doFetch(array $ids)
196197
{
197-
return $this->checkResultCode($this->client->getMulti($ids));
198+
$unserializeCallbackHandler = ini_set('unserialize_callback_func', __CLASS__.'::handleUnserializeCallback');
199+
try {
200+
return $this->checkResultCode($this->client->getMulti($ids));
201+
} catch (\Error $e) {
202+
throw new \ErrorException($e->getMessage(), $e->getCode(), E_ERROR, $e->getFile(), $e->getLine());
203+
} finally {
204+
ini_set('unserialize_callback_func', $unserializeCallbackHandler);
205+
}
198206
}
199207

200208
/**

0 commit comments

Comments
 (0)