Activate APCu on PHP 7

Fix an issue with APCus inc and dec methods on PHP 7

see https://github.com/krakjoe/apcu/issues/183#issuecomment-244038221 for details
This commit is contained in:
Morris Jobke 2016-09-01 12:30:05 +02:00
parent 1ae4a2f9e4
commit 7f8c5ed497
No known key found for this signature in database
GPG Key ID: 9CE5ED29E7FCD38A
2 changed files with 31 additions and 3 deletions

View File

@ -10,7 +10,7 @@ build:
- git submodule update --init - git submodule update --init
- NOCOVERAGE=true TEST_SELECTION=NODB ./autotest.sh sqlite - NOCOVERAGE=true TEST_SELECTION=NODB ./autotest.sh sqlite
nodb-php7.0: nodb-php7.0:
image: nextcloudci/php7.0:1.0.9 image: nextcloudci/php7.0:php7.0-1
commands: commands:
- rm -rf data/* config/config.php # TODO: remove this - temporary fix for CI issues - rm -rf data/* config/config.php # TODO: remove this - temporary fix for CI issues
- git submodule update --init - git submodule update --init

View File

@ -88,7 +88,21 @@ class APCu extends Cache implements IMemcache {
*/ */
public function inc($key, $step = 1) { public function inc($key, $step = 1) {
$this->add($key, 0); $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 * @return int | bool
*/ */
public function dec($key, $step = 1) { 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;
} }
/** /**