From: Ori Livneh Date: Wed, 22 Jul 2015 22:26:02 +0000 (-0700) Subject: Don't double-serialize values for APC X-Git-Tag: 1.31.0-rc.0~10674 X-Git-Url: http://git.cyclocoop.org/%40spipnet%40?a=commitdiff_plain;h=7aeb270474169d19617ca9fa7a5b8ceeb8e08eff;p=lhc%2Fweb%2Fwiklou.git Don't double-serialize values for APC The last time we had encountered APC errors related to serialization / unserialization was 2011. PHP's implementation has had many bugfixes since then, and HHVM's implementation is a complete rewrite. So let's stop working around alleged bugs. To prevent errors resulting from HHVM code receiving serialize()d values when it isn't expecting them, add a key suffix. Change-Id: I4b2cf1715538aa3d9163787f43eb31984a380d35 --- diff --git a/includes/libs/objectcache/APCBagOStuff.php b/includes/libs/objectcache/APCBagOStuff.php index eaf115570c..cc54fe7dd8 100644 --- a/includes/libs/objectcache/APCBagOStuff.php +++ b/includes/libs/objectcache/APCBagOStuff.php @@ -27,43 +27,39 @@ * @ingroup Cache */ class APCBagOStuff extends BagOStuff { + + /** + * @var string String to append to each APC key. This may be changed + * whenever the handling of values is changed, to prevent existing code + * from encountering older values which it cannot handle. + **/ + const KEY_SUFFIX = ':1'; + public function get( $key, &$casToken = null ) { - $val = apc_fetch( $key ); + $val = apc_fetch( $key . self::KEY_SUFFIX ); $casToken = $val; - if ( is_string( $val ) ) { - if ( $this->isInteger( $val ) ) { - $val = intval( $val ); - } else { - $val = unserialize( $val ); - } - } - return $val; } public function set( $key, $value, $exptime = 0 ) { - if ( !$this->isInteger( $value ) ) { - $value = serialize( $value ); - } - - apc_store( $key, $value, $exptime ); + apc_store( $key . self::KEY_SUFFIX, $value, $exptime ); return true; } public function delete( $key ) { - apc_delete( $key ); + apc_delete( $key . self::KEY_SUFFIX ); return true; } public function incr( $key, $value = 1 ) { - return apc_inc( $key, $value ); + return apc_inc( $key . self::KEY_SUFFIX, $value ); } public function decr( $key, $value = 1 ) { - return apc_dec( $key, $value ); + return apc_dec( $key . self::KEY_SUFFIX, $value ); } }