Skip to content

Commit

Permalink
bug #23615 [Cache] Handle serialization failures for Memcached (nicol…
Browse files Browse the repository at this point in the history
…as-grekas)

This PR was merged into the 3.3 branch.

Discussion
----------

[Cache] Handle serialization failures for Memcached

| Q             | A
| ------------- | ---
| Branch?       | 3.3
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | -
| License       | MIT
| Doc PR        | -

Fixes two issues with serialization + memcached: with the memcached extension, the default serializer is automatically selected as igbinary when possible, native php otherwise. That creates obvious migration/portability issues (ie just installing igbinary wipes out the value of your cache.)

Then, handling unserializing failures (esp. "php_incomplete_class") is a paramount feature of the component. You must be able to deal with migrating you code base without being blocked by some legacy serialized data.

Commits
-------

cccc88f [Cache] Handle unserialization failures for Memcached
  • Loading branch information
nicolas-grekas committed Jul 26, 2017
2 parents a00b05e + cccc88f commit 8907bc4
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/Symfony/Component/Cache/Traits/MemcachedTrait.php
Expand Up @@ -26,6 +26,7 @@ trait MemcachedTrait
'persistent_id' => null,
'username' => null,
'password' => null,
'serializer' => 'php',
);

private $client;
Expand Down Expand Up @@ -194,7 +195,14 @@ protected function doSave(array $values, $lifetime)
*/
protected function doFetch(array $ids)
{
return $this->checkResultCode($this->client->getMulti($ids));
$unserializeCallbackHandler = ini_set('unserialize_callback_func', __CLASS__.'::handleUnserializeCallback');
try {
return $this->checkResultCode($this->client->getMulti($ids));
} catch (\Error $e) {
throw new \ErrorException($e->getMessage(), $e->getCode(), E_ERROR, $e->getFile(), $e->getLine());
} finally {
ini_set('unserialize_callback_func', $unserializeCallbackHandler);
}
}

/**
Expand Down

0 comments on commit 8907bc4

Please sign in to comment.