Example #1
0
 public function cas($key, $old, $new)
 {
     if (CACHE_STATUS) {
         apc_cas($key, $old, $new);
     }
     return false;
 }
Example #2
0
 public function cas($key, $old, $new)
 {
     if (_cacheStatus) {
         apc_cas($key, $old, $new);
     }
     return FALSE;
 }
Example #3
0
 /**
  * Compare and set
  *
  * @param string $key
  * @param mixed $old
  * @param mixed $new
  * @return bool
  */
 public function cas($key, $old, $new)
 {
     // apc only does cas for ints
     if (is_int($old) and is_int($new)) {
         return apc_cas($this->getPrefix() . $key, $old, $new);
     } else {
         return $this->casEmulated($key, $old, $new);
     }
 }
Example #4
0
 public static function cas($k, $ov, $nv)
 {
     if (function_exists('apc_cas')) {
         return apc_cas($k, $ov, $nv);
     } elseif (function_exists('apcu_cas')) {
         return apcu_cas($k, $ov, $nv);
     }
     return false;
 }
Example #5
0
 public function updateGauge(array $data)
 {
     $valueKey = $this->valueKey($data);
     if ($data['command'] == Adapter::COMMAND_SET) {
         apc_store($valueKey, $this->toInteger($data['value']));
         apc_store($this->metaKey($data), json_encode($this->metaData($data)));
     } else {
         $new = apc_add($valueKey, $this->toInteger(0));
         if ($new) {
             apc_store($this->metaKey($data), json_encode($this->metaData($data)));
         }
         // Taken from https://github.com/prometheus/client_golang/blob/66058aac3a83021948e5fb12f1f408ff556b9037/prometheus/value.go#L91
         $done = false;
         while (!$done) {
             $old = apc_fetch($valueKey);
             $done = apc_cas($valueKey, $old, $this->toInteger($this->fromInteger($old) + $data['value']));
         }
     }
 }
Example #6
0
 function apcu_cas($key, $old, $new)
 {
     return apc_cas($key, $old, $new);
 }
 /**
  * Internal method to set an item only if token matches
  *
  * @param  mixed  $token
  * @param  string $normalizedKey
  * @param  mixed  $value
  * @return bool
  * @see    getItem()
  * @see    setItem()
  */
 protected function internalCheckAndSetItem(&$token, &$normalizedKey, &$value)
 {
     if (is_int($token) && is_int($value)) {
         return apc_cas($normalizedKey, $token, $value);
     }
     return parent::internalCheckAndSetItem($token, $normalizedKey, $value);
 }
Example #8
0
 /**
  * Sets a new value if a key has a certain value.
  *
  * Sets a new value if a key has a certain value. This function only works
  * when $old and $new are longs.
  *
  * @param string $key Key of the value to compare and set.
  * @param int    $old The value to compare the key against.
  * @param int    $new The value to set the key to.
  *
  * @return bool TRUE on success, FALSE on failure.
  */
 public function cas($key, $old, $new)
 {
     return apc_cas($this->persistentId . 'd ' . $key, $old, $new);
 }
Example #9
0
error_reporting(E_ALL);
ini_set("display_errors", 1);
echo "<pre>";
$is_apc_installed = extension_loaded('apc');
echo "[{$is_apc_installed}]" . PHP_EOL;
// Example #1 A apc_add() example
$bar = 'BAR';
apc_add('foo', $bar);
print_r(apc_fetch('foo'));
//apc_delete('foo');
echo "\n";
$bar = 'NEVER GETS SET NEW ';
apc_add('foonew', $bar);
print_r(apc_fetch('foonew'));
apc_delete('foo');
echo "\n";
apc_cas('foo', 1, 2);
print_r(apc_fetch('foo'));
print_r(apc_cache_info());
print_r(apc_bin_dump());
apc_bin_dumpfile(array(), array('foo', 'foonew'), "aa.txt");
echo "<br/>";
echo "<br/>";
echo "<br/>";
echo "<br/>";
echo "<br/>";
echo "<br/>";
echo "<br/>";
echo "<br/>";
echo "<br/>";
echo "<br/>";
<?php

/**
 * (c) Liviu Balan <*****@*****.**>
 * http://www.liviubalan.com/
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */
/**
 * apc_cas
 * Updates an old value with a new value
 *
 * @author Liviu Balan <*****@*****.**>
 * @link http://php.net/manual/en/function.apc-cas.php
 * @link https://en.wikipedia.org/wiki/Compare-and-swap
 */
apc_store('foobar', 2);
echo '$foobar = 2' . '<br />';
echo '$foobar == 1 ? 2 : 1 = ', (apc_cas('foobar', 1, 2) ? 'ok' : 'fail') . '<br />';
echo '$foobar == 2 ? 1 : 2 = ', (apc_cas('foobar', 2, 1) ? 'ok' : 'fail') . '<br />';
echo '$foobar = ', apc_fetch('foobar') . '<br />';
echo '$f__bar == 1 ? 2 : 1 = ', (apc_cas('f__bar', 1, 2) ? 'ok' : 'fail') . '<br />';
apc_store('perfection', 'xyz');
echo '$perfection == 2 ? 1 : 2 = ', (apc_cas('perfection', 2, 1) ? 'ok' : 'epic fail') . '<br />';
echo '$foobar = ', apc_fetch('foobar') . '<br />';
Example #11
0
 /**
  * Internal method to set an item only if token matches
  *
  * @param  mixed  $token
  * @param  string $normalizedKey
  * @param  mixed  $value
  * @return bool
  * @see    getItem()
  * @see    setItem()
  */
 protected function internalCheckAndSetItem(&$token, &$normalizedKey, &$value)
 {
     return apc_cas($normalizedKey, $token, $value);
 }
Example #12
0
File: 9.php Project: badlamer/hhvm
<?php

apc_store("ts", 12);
apc_cas("ts", 12, 15);
if (apc_fetch("ts") !== 15) {
    echo "no\n";
}
apc_cas("ts", 12, 18);
if (apc_fetch("ts") !== 15) {
    echo "no\n";
}
echo "ok\n";