Skip to content

Commit

Permalink
Merge pull request #195 from tedious/hhvm_apc
Browse files Browse the repository at this point in the history
Modified APC to deal with HHVM bug
  • Loading branch information
tedivm committed Nov 23, 2014
2 parents de62c33 + f2a9430 commit c75fe27
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
3 changes: 1 addition & 2 deletions .travis.yml
Expand Up @@ -23,6 +23,5 @@ services:
- memcached

matrix:
allow_failures:
- php: hhvm
allow_failures:
- php: hhvm-nightly
22 changes: 14 additions & 8 deletions src/Stash/Driver/Apc.php
Expand Up @@ -115,10 +115,16 @@ public function clear($key = null)
} else {
$keyRegex = '[' . $this->makeKey($key) . '*]';
$chunkSize = isset($this->chunkSize) && is_numeric($this->chunkSize) ? $this->chunkSize : 100;
$it = new \APCIterator('user', $keyRegex, \APC_ITER_KEY, $chunkSize);
foreach ($it as $key) {
apc_delete($key);
}

do {
$emptyIterator = true;
$it = new \APCIterator('user', $keyRegex, \APC_ITER_KEY, $chunkSize);
foreach ($it as $item) {
$emptyIterator = false;
apc_delete($item['key']);
}
} while (!$emptyIterator);

}

return true;
Expand All @@ -132,14 +138,14 @@ public function purge()
$now = time();
$keyRegex = '[' . $this->makeKey(array()) . '*]';
$chunkSize = isset($this->chunkSize) && is_numeric($this->chunkSize) ? $this->chunkSize : 100;

$it = new \APCIterator('user', $keyRegex, \APC_ITER_KEY, $chunkSize);
foreach ($it as $key) {
foreach ($it as $item) {
$success = null;
$data = apc_fetch($key, $success);
$data = $data[$key['key']];
$data = apc_fetch($item['key'], $success);

if ($success && is_array($data) && $data['expiration'] <= $now) {
apc_delete($key);
apc_delete($item['key']);
}
}

Expand Down

0 comments on commit c75fe27

Please sign in to comment.