]> source.dussan.org Git - nextcloud-server.git/commitdiff
Activate APCu on PHP 7
authorMorris Jobke <hey@morrisjobke.de>
Thu, 1 Sep 2016 10:30:05 +0000 (12:30 +0200)
committerMorris Jobke <hey@morrisjobke.de>
Tue, 8 Nov 2016 11:29:25 +0000 (12:29 +0100)
Fix an issue with APCus inc and dec methods on PHP 7

see https://github.com/krakjoe/apcu/issues/183#issuecomment-244038221 for details

Signed-off-by: Morris Jobke <hey@morrisjobke.de>
lib/private/Memcache/APCu.php

index 713ed152648c71acf969f3d89962467605d6caab..70f0d73d2d483bb4bfc3c47f1fb4141e113e9f06 100644 (file)
@@ -88,7 +88,21 @@ class APCu extends Cache implements IMemcache {
         */
        public function inc($key, $step = 1) {
                $this->add($key, 0);
-               return apcu_inc($this->getPrefix() . $key, $step);
+               /**
+                * TODO - hack around a PHP 7 specific issue in APCu
+                *
+                * on PHP 7 the apcu_inc method on a non-existing object will increment
+                * "0" and result in "1" as value - therefore we check for existence
+                * first
+                *
+                * on PHP 5.6 this is not the case
+                *
+                * see https://github.com/krakjoe/apcu/issues/183#issuecomment-244038221
+                * for details
+                */
+               return apcu_exists($this->getPrefix() . $key)
+                       ? apcu_inc($this->getPrefix() . $key, $step)
+                       : false;
        }
 
        /**
@@ -99,7 +113,21 @@ class APCu extends Cache implements IMemcache {
         * @return int | bool
         */
        public function dec($key, $step = 1) {
-               return apcu_dec($this->getPrefix() . $key, $step);
+               /**
+                * TODO - hack around a PHP 7 specific issue in APCu
+                *
+                * on PHP 7 the apcu_dec method on a non-existing object will decrement
+                * "0" and result in "-1" as value - therefore we check for existence
+                * first
+                *
+                * on PHP 5.6 this is not the case
+                *
+                * see https://github.com/krakjoe/apcu/issues/183#issuecomment-244038221
+                * for details
+                */
+               return apcu_exists($this->getPrefix() . $key)
+                       ? apcu_dec($this->getPrefix() . $key, $step)
+                       : false;
        }
 
        /**