Example #1
0
File: APCU.php Project: techart/tao
 public function get_all_keys()
 {
     $info = apcu_cache_info();
     $list = array();
     foreach ($info['cache_list'] as $cl) {
         $list[] = $cl['key'];
     }
     return $list;
 }
Example #2
0
 /**
  * {@inheritDoc}
  */
 public function ttl($key)
 {
     $key = $this->getFinalKey($key);
     $infos = apcu_cache_info();
     foreach ($infos['cache_list'] as $entry) {
         if ($entry['info'] == $key) {
             return $entry['ttl'];
         }
     }
     return false;
 }
Example #3
0
 /**
  * {@inheritdoc}
  */
 protected function doGetStats()
 {
     $info = apcu_cache_info('', true);
     $sma = apcu_sma_info();
     // @TODO - Temporary fix @see https://github.com/krakjoe/apcu/pull/42
     if (PHP_VERSION_ID >= 50500) {
         $info['num_hits'] = isset($info['num_hits']) ? $info['num_hits'] : $info['nhits'];
         $info['num_misses'] = isset($info['num_misses']) ? $info['num_misses'] : $info['nmisses'];
         $info['start_time'] = isset($info['start_time']) ? $info['start_time'] : $info['stime'];
     }
     return array(Cache::STATS_HITS => $info['num_hits'], Cache::STATS_MISSES => $info['num_misses'], Cache::STATS_UPTIME => $info['start_time'], Cache::STATS_MEMORY_USAGE => $info['mem_size'], Cache::STATS_MEMORY_AVAILABLE => $sma['avail_mem']);
 }
Example #4
0
 /**
  * init apcu backend: test APCu availability and set alive status
  */
 protected function _init()
 {
     /* verify apcu functions exist, apcu extension is loaded */
     if (!function_exists('apcu_cache_info')) {
         $this->log(__translate__('APCu extension missing', 'wp-ffpc'));
         return false;
     }
     /* verify apcu is working */
     if (@apcu_cache_info("user") != false) {
         $this->log(__translate__('backend OK', 'wp-ffpc'));
         $this->alive = true;
     }
 }
Example #5
0
 public function testApcu()
 {
     $key = __CLASS__;
     apcu_delete($key);
     $this->assertFalse(apcu_exists($key));
     $this->assertTrue(apcu_add($key, 123));
     $this->assertTrue(apcu_exists($key));
     $this->assertSame(array($key => -1), apcu_add(array($key => 123)));
     $this->assertSame(123, apcu_fetch($key));
     $this->assertTrue(apcu_store($key, 124));
     $this->assertSame(124, apcu_fetch($key));
     $this->assertSame(125, apcu_inc($key));
     $this->assertSame(124, apcu_dec($key));
     $this->assertTrue(apcu_cas($key, 124, 123));
     $this->assertFalse(apcu_cas($key, 124, 123));
     $this->assertTrue(apcu_delete($key));
     $this->assertFalse(apcu_delete($key));
     $this->assertArrayHasKey('cache_list', apcu_cache_info());
 }
Example #6
0
 /**
  * Get all the keys currently in the cache.
  * @see apc_cache_info()
  *
  * @return array
  */
 public function getKeys()
 {
     $cache = false;
     $key = false;
     $keys = array();
     if (function_exists('apcu_cache_info')) {
         $cache = apcu_cache_info('user');
         $key = 'key';
     } elseif (function_exists('apc_cache_info')) {
         $cache = apc_cache_info('user');
         $key = 'info';
     }
     if ($cache && $key) {
         foreach ($cache['cache_list'] as $entry) {
             $keys[] = $entry[$key];
         }
     }
     return $keys;
 }
Example #7
0
 /**
  * Delete one or several data from cache (* joker can be used, but avoid it !)
  * 	E.g.: delete('*'); delete('my_prefix_*'); delete('my_key_name');
  *
  * @param string $key Cache key
  * @return bool Whether the key was deleted
  */
 public function delete($key)
 {
     if ($key == '*') {
         $this->flush();
     } elseif (strpos($key, '*') === false) {
         $this->_delete($key);
     } else {
         $pattern = str_replace('\\*', '.*', preg_quote($key));
         $cache_info = $this->apcu ? apcu_cache_info('') : apc_cache_info('');
         foreach ($cache_info['cache_list'] as $entry) {
             if (isset($entry['key'])) {
                 $key = $entry['key'];
             } else {
                 $key = $entry['info'];
             }
             if (preg_match('#^' . $pattern . '$#', $key)) {
                 $this->_delete($key);
             }
         }
     }
     return true;
 }
Example #8
0
 /**
  * Garbage collect expired cache data
  *
  * @return  boolean
  *
  * @since   3.5
  */
 public function gc()
 {
     $allinfo = apcu_cache_info();
     $keys = $allinfo['cache_list'];
     $secret = $this->_hash;
     foreach ($keys as $key) {
         // The internal key name changed with APCu 4.0.7 from key to info
         $internalKey = isset($key['info']) ? $key['info'] : $key['key'];
         if (strpos($internalKey, $secret . '-cache-')) {
             apcu_fetch($internalKey);
         }
     }
     return true;
 }
Example #9
0
<?php

if (!function_exists('apcu_cache_info')) {
    ?>
    <p class="alert alert-danger">You do not have APCu installed</p>
    <?php 
    return;
}
/**
 * Fetch configuration and status information
 */
$info = apcu_cache_info();
//echo \Dsc\Debug::dump(array_keys($info));
$mem = apcu_sma_info();
/**
 * Turn bytes into a human readable format
 * @param $bytes
 */
function size_for_humans($bytes)
{
    if ($bytes > 1048576) {
        return sprintf("%.2f&nbsp;MB", $bytes / 1048576);
    } elseif ($bytes > 1024) {
        return sprintf("%.2f&nbsp;kB", $bytes / 1024);
    } else {
        return sprintf("%d&nbsp;bytes", $bytes);
    }
}
?>
            
            <div class="panel panel-default">
Example #10
0
if (!$show_specific) {
    $response['name'] = gethostname();
    $response['php_version'] = PHP_VERSION;
}
// OpCache //
if (!$show_specific) {
    if (function_exists('opcache_is_script_cached')) {
        // Technically, this is checking if this file is cached //
        $response['opcache_enabled'] = opcache_is_script_cached(__FILE__);
    }
}
// APCu //
if (defined('CMW_USING_APCU') && !$show_specific) {
    $response['apcu_api_version'] = phpversion('apcu');
    if (function_exists('apcu_cache_info')) {
        $response['apcu_uptime'] = time() - intval(apcu_cache_info(true)['start_time']);
    }
}
// Database //
if (defined('CMW_USING_DB') && $show_db) {
    $response['db_api_version'] = phpversion('mysqli');
    if ($is_admin) {
        require_once __DIR__ . "/../../db.php";
        $db_data = db_QueryFetchPair("show VARIABLES like \"%version%\"");
        $response['db_version'] = $db_data['version'];
        $db_data = db_QueryFetchPair("show global status where Variable_Name = 'Uptime';");
        $response['db_uptime'] = time_offset() + intval($db_data['Uptime']);
    }
}
// Redis //
if (defined('CMW_USING_REDIS') && $show_redis) {
Example #11
0
 /**
  * Delete all keys from the cache. This will clear every cache config using APC.
  *
  * @param bool $check If true, nothing will be cleared, as entries are removed
  *    from APC as they expired. This flag is really only used by FileEngine.
  * @return bool True Returns true.
  */
 public function clear($check)
 {
     if ($check) {
         return true;
     }
     $func = $this->_apcExtension . '_delete';
     if (class_exists('APCIterator', false)) {
         $iterator = new APCIterator('user', '/^' . preg_quote($this->settings['prefix'], '/') . '/', APC_ITER_NONE);
         $func($iterator);
         return true;
     }
     $cache = $this->_apcExtension === 'apc' ? apc_cache_info('user') : apcu_cache_info();
     foreach ($cache['cache_list'] as $key) {
         if (strpos($key['info'], $this->settings['prefix']) === 0) {
             $func($key['info']);
         }
     }
     return true;
 }
Example #12
0
 /**
  * {@inheritdoc}
  */
 protected function doGetStats()
 {
     $info = apcu_cache_info(true);
     $sma = apcu_sma_info();
     return array(Cache::STATS_HITS => $info['num_hits'], Cache::STATS_MISSES => $info['num_misses'], Cache::STATS_UPTIME => $info['start_time'], Cache::STATS_MEMORY_USAGE => $info['mem_size'], Cache::STATS_MEMORY_AVAILABLE => $sma['avail_mem']);
 }
Example #13
0
 public function info($type = 'user', $limit = false)
 {
     return apcu_cache_info($type, $limit);
 }
Example #14
0
 public function apcu_get()
 {
     $res = apcu_fetch($this->key);
     //var_dump($res);
     return apcu_cache_info();
 }
Example #15
0
    }
    /**
     * @param string $type
     * @param bool $limited
     * @return array|bool Array of cached data (and meta-data) or FALSE on failure.
     */
    function apcu_cache_info($type = '', $limited = false)
    {
        return apc_cache_info($type, $limited);
    }
    class APCUIterator extends APCIterator
    {
    }
}
$smaInfo = apcu_sma_info();
$cacheInfo = apcu_cache_info();
?>

<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
</head>
<body>
    <table>
        <tr>
            <td colspan="2">
               <h2>Cache Information</h2>
            </td>
        </tr>
Example #16
0
            $AUTHENTICATED = 1;
        }
    }
}
// clear cache
if ($AUTHENTICATED && isset($MYREQUEST['CC']) && $MYREQUEST['CC']) {
    apcu_clear_cache();
}
if ($AUTHENTICATED && !empty($MYREQUEST['DU'])) {
    apcu_delete($MYREQUEST['DU']);
}
if (!function_exists('apcu_cache_info')) {
    echo "No cache info available.  APC does not appear to be running.";
    exit;
}
$cache = apcu_cache_info();
$mem = apcu_sma_info();
// don't cache this page
//
header("Cache-Control: no-store, no-cache, must-revalidate");
// HTTP/1.1
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
// HTTP/1.0
function duration($ts)
{
    global $time;
    $years = (int) (($time - $ts) / (7 * 86400) / 52.177457);
    $rem = (int) ($time - $ts - $years * 52.177457 * 7 * 86400);
    $weeks = (int) ($rem / (7 * 86400));
    $days = (int) ($rem / 86400) - $weeks * 7;
Example #17
0
 /**
  * Delete all keys from the cache. This will clear every cache config using APC.
  *
  * @param bool $check If true, nothing will be cleared, as entries are removed
  *    from APC as they expired. This flag is really only used by FileEngine.
  * @return bool True Returns true.
  */
 public function clear($check)
 {
     if ($check) {
         return true;
     }
     if (class_exists('APCUIterator', false)) {
         $iterator = new APCUIterator('/^' . preg_quote($this->_config['prefix'], '/') . '/', APC_ITER_NONE);
         apcu_delete($iterator);
         return true;
     }
     $cache = apcu_cache_info();
     foreach ($cache['cache_list'] as $key) {
         if (strpos($key['info'], $this->_config['prefix']) === 0) {
             apcu_delete($key['info']);
         }
     }
     return true;
 }
Example #18
0
<?php

/* Uptime Check */
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(-1);
require_once __DIR__ . "/../config.php";
require_once __DIR__ . "/../api.php";
// REMEMBER: The CloudFlare IPs are not whitelisted //
if (!core_OnWhitelist($_SERVER['REMOTE_ADDR'], CMW_ACCESS_DATA)) {
    json_EmitError(401);
}
$response = json_NewResponse();
if (defined('CMW_USING_APCU')) {
    $response['apcu'] = ["uptime" => time() - intval(apcu_cache_info("user")['start_time'])];
}
if (defined('CMW_USING_REDIS')) {
    $redis = new Redis();
    $redis->connect(CMW_REDIS_HOST);
    $response['redis'] = ["uptime" => intval($redis->info('default')['uptime_in_seconds'])];
    $redis->close();
}
if (defined('CMW_USING_DB')) {
    require_once __DIR__ . "/../db.php";
    db_connect();
    $db_data = db_FetchArrayPair("show global status where Variable_Name = 'Uptime';");
    $response['db'] = ["uptime" => intval($db_data['Uptime'])];
    db_close();
}
if (defined('CMW_USING_MEMCACHED')) {
    $m = new Memcached();
Example #19
0
 /**
  * Get all cached data
  *
  * @return  array
  */
 public function all()
 {
     $allinfo = $this->apcu ? apcu_cache_info() : apc_cache_info('user');
     $keys = $allinfo['cache_list'];
     $hash = $this->options['hash'];
     $data = array();
     foreach ($keys as $key) {
         $name = $key['info'];
         $namearr = explode('-', $name);
         if ($namearr !== false && $namearr[0] == $secret && $namearr[1] == 'cache') {
             $group = $namearr[2];
             if (!isset($data[$group])) {
                 $item = new Auditor($group);
             } else {
                 $item = $data[$group];
             }
             $item->tally($key['mem_size'] / 1024);
             $data[$group] = $item;
         }
     }
     return $data;
 }
Example #20
0
 /**
  * Return apcu cache info
  * @param \Slim\Http\Request $req http request
  * @param \Slim\Http\Response $res http response
  */
 public function status(Request $req, Response $res)
 {
     return $res->withStatus(200)->withHeader('Content-type', 'application/json')->write(json_encode(apcu_cache_info(), JSON_PRETTY_PRINT));
 }
Example #21
0
 /**
  * Force garbage collect expired cache data as items are removed only on fetch!
  *
  * @return  boolean  True on success, false otherwise.
  *
  * @since   3.5
  */
 public function gc()
 {
     $allinfo = apcu_cache_info();
     $keys = $allinfo['cache_list'];
     $secret = $this->_hash;
     foreach ($keys as $key) {
         if (strpos($key['info'], $secret . '-cache-')) {
             apcu_fetch($key['info']);
         }
     }
     return true;
 }
Example #22
0
 function apc_cache_info($cache_type = "", $limited = false)
 {
     return apcu_cache_info($cache_type, $limited);
 }
Example #23
0
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 *
 * @author     Kenny Freeman <*****@*****.**>
 * @copyright  2016 Kenny Freeman
 * @license    https://opensource.org/licenses/ISC
 */
// Ensure cache info functions exist
$opc_ci = function_exists('opcache_get_status');
// Apc can be apcu or apc
$apc_ci = function_exists('apc_cache_info');
$apcu_ci = function_exists('apcu_cache_info');
// Apc Shared Memory Allocation (sma)
$apc_sma_ci = function_exists('apc_sma_info');
// Get cache info
$oc_metrics = $opc_ci ? opcache_get_status(False) : array();
$apc_metrics = $apcu_ci ? apcu_cache_info(True) : array();
$sma_metrics = $apc_sma_ci ? apc_sma_info(True) : array();
// Apc Metrics if Apcu not available
if ($apc_ci && !$apcu_ci) {
    // older php install - can have (cache_type, limited) or (limited)
    $ref_apc = new ReflectionFunction('apc_cache_info');
    $nargs = count($ref_apc->getParameters());
    switch ($nargs) {
        case 1:
            $apc_metrics = apc_cache_info(True);
            break;
        case 2:
            // old cache that still has opcache in it..
            $apc_metrics = apc_cache_info("user", True);
            break;
        default:
Example #24
0
 /**
  * Remove all items from the cache.
  *
  * @return void
  */
 public function cacheList()
 {
     $list = $this->apcu ? apcu_cache_info() : apc_cache_info();
     return isset($list['cache_list']) ? $list['cache_list'] : [];
 }
Example #25
0
 /**
  * Delete expired cache data
  *
  * @return  boolean  True on success, false otherwise.
  *
  * @since   1.2.7
  */
 public function gc()
 {
     $cache_info = apcu_cache_info();
     $keys = $cache_info['cache_list'];
     foreach ($keys as $key) {
         // If APCu is being used for this adapter, the internal key name changed with APCu 4.0.7 from key to info
         $internalKey = isset($key['info']) ? $key['info'] : $key['key'];
         if (strpos($internalKey, $this->secret . '-cache-')) {
             apcu_fetch($internalKey);
         }
     }
     return true;
 }
Example #26
0
 /**
  * Garbage collect expired cache data
  *
  * @return  boolean
  *
  * @since   3.5
  */
 public function gc()
 {
     $allinfo = apcu_cache_info();
     $keys = $allinfo['cache_list'];
     $secret = $this->_hash;
     foreach ($keys as $key) {
         if (isset($key['info'])) {
             // The internal key name changed with APCu 4.0.7 from key to info
             $internalKey = $key['info'];
         } elseif (isset($key['entry_name'])) {
             // Some APCu modules changed the internal key name from key to entry_name
             $internalKey = $key['entry_name'];
         } else {
             // A fall back for the old internal key name
             $internalKey = $key['key'];
         }
         if (strpos($internalKey, $secret . '-cache-')) {
             apcu_fetch($internalKey);
         }
     }
     return true;
 }
Example #27
0
 function apc_cache_info($cache_type, $limited = false)
 {
     apcu_cache_info($cache_type, $limited);
 }