Example #1
0
 /**
  * Test if a cache is available or not (for the given id)
  *
  * @param  string $id cache id
  * @return mixed false (a cache is not available) or "last modified" timestamp (int) of the available cache record
  */
 public function test($id)
 {
     $tmp = zend_shm_cache_fetch($this->_options['namespace'] . '::' . $id);
     if ($tmp !== null && $tmp !== false) {
         return true;
     }
     return false;
 }
Example #2
0
 public function fetch($key)
 {
     $data = zend_shm_cache_fetch("MongoObject::{$key}");
     if ($data === false) {
         $data = null;
     }
     return $data;
 }
Example #3
0
 protected function _get($key)
 {
     $data = zend_shm_cache_fetch($this->key($key));
     if ($data === null) {
         return self::NOT_FOUND;
     }
     return $data;
 }
Example #4
0
 /**
  * @param \Psr\Cache\CacheItemInterface $item
  * @return mixed
  */
 protected function driverRead(CacheItemInterface $item)
 {
     $data = zend_shm_cache_fetch($item->getKey());
     if ($data === false) {
         return null;
     }
     return $data;
 }
Example #5
0
 /**
  * @see SugarCacheAbstract::_getExternal()
  */
 protected function _getExternal($key)
 {
     $raw_cache_value = zend_shm_cache_fetch($key);
     if ($raw_cache_value === false) {
         return null;
     }
     return is_string($raw_cache_value) ? unserialize($raw_cache_value) : $raw_cache_value;
 }
 function get($key)
 {
     $value = parent::get($key);
     if (!is_null($value)) {
         return $value;
     }
     $raw_cache_value = zend_shm_cache_fetch($this->_realKey($key));
     $cache_value = is_string($raw_cache_value) ? unserialize($raw_cache_value) : $raw_cache_value;
     return $this->_processGet($key, $cache_value);
 }
Example #7
0
 /**
  * 获取远程URL,并带缓存$url是URL,time是缓时间,秒为单位,默认300
  */
 public static function geturl($url, $time = 300)
 {
     $md5 = md5($url);
     $cached = zend_shm_cache_fetch($md5);
     //从内存缓存读取
     if ($cached === false || !empty($_GET['update'])) {
         $cached = file_get_contents($url);
         zend_shm_cache_store($md5, $cached, $time);
         //存至内存,最后一个是过期时间,单位为秒
         return $cached;
     } else {
         return $cached;
     }
 }
Example #8
0
 /**
  * {@inheritdoc}
  */
 protected function _doContains($id)
 {
     return zend_shm_cache_fetch($id) !== FALSE;
 }
Example #9
0
 /**
  * Get a cache variable
  *
  * Retrieve a variable from the cache and return it's
  * value to the user.
  *
  * @param  string $name  The name of the cache variable to retrieve.
  *
  * @return mixed         The value of the retrieved variable or false if
  *                       variable isn't found.
  */
 public function get($name)
 {
     return zend_shm_cache_fetch($name);
 }
Example #10
0
 /**
  * Fetch multiple items from Zend Data SHM Cache
  *
  * @param  array $internalKeys
  * @return array All found items
  * @throws Exception\RuntimeException
  */
 protected function zdcFetchMulti(array $internalKeys)
 {
     $items = zend_shm_cache_fetch($internalKeys);
     if ($items === false) {
         throw new Exception\RuntimeException("zend_shm_cache_fetch(<array>) failed");
     }
     return $items;
 }
Example #11
0
 public function get($key)
 {
     $safeKey = $this->makeKey($key);
     $ret = @zend_shm_cache_fetch($safeKey);
     return $ret;
 }
Example #12
0
/**
 * Gets the value from the cache specified by key, so long as it is not older than ttl seconds.
 * - It may often "miss", so shouldn't be depended on.
 * - It supports the same as cache_put_data().
 *
 * @param string $key
 * @param int $ttl = 120
 */
function cache_get_data($key, $ttl = 120)
{
    global $cache_memcached, $memcached, $cache_hits, $cache_count, $db_show_debug;
    global $cache_accelerator, $cache_enable, $expired;
    if (empty($cache_enable)) {
        return;
    }
    $cache_count = isset($cache_count) ? $cache_count + 1 : 1;
    if (isset($db_show_debug) && $db_show_debug === true) {
        $cache_hits[$cache_count] = array('k' => $key, 'd' => 'get');
        $st = microtime(true);
    }
    $key = cache_get_key($key);
    switch ($cache_accelerator) {
        case 'memcached':
            // Okay, let's go for it memcached!
            if ((function_exists('memcache_get') || function_exists('memcached_get')) && !empty($cache_memcached)) {
                // Not connected yet?
                if (empty($memcached)) {
                    get_memcached_server();
                }
                if (!$memcached) {
                    return null;
                }
                $value = function_exists('memcache_get') ? memcache_get($memcached, $key) : memcached_get($memcached, $key);
            }
            break;
        case 'eaccelerator':
            // Again, eAccelerator.
            if (function_exists('eaccelerator_get')) {
                $value = eaccelerator_get($key);
            }
            break;
        case 'mmcache':
            // The older, but ever-stable, Turck MMCache...
            if (function_exists('mmcache_get')) {
                $value = mmcache_get($key);
            }
            break;
        case 'apc':
        case 'apcu':
            // This is the free APC or APCu from PECL.
            if (function_exists('apc_fetch')) {
                $value = apc_fetch($key . 'elkarte');
            }
            break;
        case 'zend':
            // Zend's pricey stuff.
            if (function_exists('zend_shm_cache_fetch')) {
                $value = zend_shm_cache_fetch('ELK::' . $key);
            } elseif (function_exists('output_cache_get')) {
                $value = output_cache_get($key, $ttl);
            }
            break;
        case 'xcache':
            if (function_exists('xcache_get') && ini_get('xcache.var_size') > 0) {
                $value = xcache_get($key);
            }
            break;
        default:
            // Otherwise it's ElkArte data!
            if (file_exists(CACHEDIR . '/data_' . $key . '.php') && filesize(CACHEDIR . '/data_' . $key . '.php') > 10) {
                // php will cache file_exists et all, we can't 100% depend on its results so proceed with caution
                @(include CACHEDIR . '/data_' . $key . '.php');
                if (!empty($expired) && isset($value)) {
                    @unlink(CACHEDIR . '/data_' . $key . '.php');
                    unset($value);
                }
            }
            break;
    }
    if (isset($db_show_debug) && $db_show_debug === true) {
        $cache_hits[$cache_count]['t'] = microtime(true) - $st;
        $cache_hits[$cache_count]['s'] = isset($value) ? strlen($value) : 0;
    }
    if (function_exists('call_integration_hook') && isset($value)) {
        call_integration_hook('cache_get_data', array($key, $ttl, $value));
    }
    return empty($value) ? null : @unserialize($value);
}
 /**
  * {@inheritdoc}
  */
 protected function doContains($id)
 {
     return false !== zend_shm_cache_fetch($id);
 }
 /**
  * {@inheritdoc}
  */
 public function get($key)
 {
     return zend_shm_cache_fetch($key);
 }
Example #15
0
 /**
  * Stores a value identified by a key into cache if the cache does not contain this key.
  * This is the implementation of the method declared in the parent class.
  *
  * @param string $key the key identifying the value to be cached
  * @param string $value the value to be cached
  * @param integer $duration the number of seconds in which the cached value will expire. 0 means never expire.
  * @return boolean true if the value is successfully stored into cache, false otherwise
  */
 protected function addValue($key, $value, $duration)
 {
     return zend_shm_cache_fetch($key) === null ? $this->setValue($key, $value, $duration) : false;
 }
Example #16
0
/**
 * Gets the value from the cache specified by key, so long as it is not older than ttl seconds.
 * - It may often "miss", so shouldn't be depended on.
 * - It supports the same as cache_put_data().
 *
 * @param string $key
 * @param int $ttl = 120
 * @return string
 */
function cache_get_data($key, $ttl = 120)
{
    global $boardurl, $sourcedir, $modSettings, $memcached;
    global $cache_hits, $cache_count, $db_show_debug, $cachedir;
    global $cache_accelerator, $cache_enable;
    if (empty($cache_enable)) {
        return;
    }
    $cache_count = isset($cache_count) ? $cache_count + 1 : 1;
    if (isset($db_show_debug) && $db_show_debug === true) {
        $cache_hits[$cache_count] = array('k' => $key, 'd' => 'get');
        $st = microtime();
    }
    $key = md5($boardurl . filemtime($sourcedir . '/Load.php')) . '-SMF-' . strtr($key, ':/', '-_');
    switch ($cache_accelerator) {
        case 'memcache':
            // Okay, let's go for it memcached!
            if ((function_exists('memcache_get') || function_exists('memcached_get')) && isset($modSettings['cache_memcached']) && trim($modSettings['cache_memcached']) != '') {
                // Not connected yet?
                if (empty($memcached)) {
                    get_memcached_server();
                }
                if (!$memcached) {
                    return null;
                }
                $value = function_exists('memcache_get') ? memcache_get($cache['connection'], $key) : memcached_get($cache['connection'], $key);
            }
            break;
        case 'eaccelerator':
            // Again, eAccelerator.
            if (function_exists('eaccelerator_get')) {
                $value = eaccelerator_get($key);
            }
            break;
        case 'mmcache':
            // The older, but ever-stable, Turck MMCache...
            if (function_exists('mmcache_get')) {
                $value = mmcache_get($key);
            }
            break;
        case 'apc':
            // This is the free APC from PECL.
            if (function_exists('apc_fetch')) {
                $value = apc_fetch($key . 'smf');
            }
            break;
        case 'zend':
            // Zend's pricey stuff.
            if (function_exists('zend_shm_cache_fetch')) {
                $value = zend_shm_cache_fetch('SMF::' . $key, $ttl);
            } elseif (function_exists('output_cache_get')) {
                $value = output_cache_get($key, $ttl);
            }
            break;
        case 'xcache':
            if (function_exists('xcache_get') && ini_get('xcache.var_size') > 0) {
                $value = xcache_get($key);
            }
            break;
        default:
            // Otherwise it's SMF data!
            if (file_exists($cachedir . '/data_' . $key . '.php') && filesize($cachedir . '/data_' . $key . '.php') > 10) {
                // php will cache file_exists et all, we can't 100% depend on its results so proceed with caution
                @(include $cachedir . '/data_' . $key . '.php');
                if (!empty($expired) && isset($value)) {
                    @unlink($cachedir . '/data_' . $key . '.php');
                    unset($value);
                }
            }
            break;
    }
    if (isset($db_show_debug) && $db_show_debug === true) {
        $cache_hits[$cache_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st));
        $cache_hits[$cache_count]['s'] = isset($value) ? strlen($value) : 0;
    }
    if (function_exists('call_integration_hook')) {
        call_integration_hook('cache_get_data', array(&$key, &$ttl, &$value));
    }
    return empty($value) ? null : @unserialize($value);
}
Example #17
0
 /**
  * Stores a value identified by a key into cache if the cache does not contain this key.
  * This is the implementation of the method declared in the parent class.
  *
  * @param string $key the key identifying the value to be cached
  * @param string $value the value to be cached
  * @param integer $expire the number of seconds in which the cached value will expire. 0 means never expire.
  * @return boolean true if the value is successfully stored into cache, false otherwise
  */
 protected function addValue($key, $value, $expire)
 {
     return NULL === zend_shm_cache_fetch($key) ? $this->setValue($key, $value, $expire) : false;
 }
 /**
  * Read datas with $uid key
  * @param mixed $uid
  * @return mixed
  */
 public function read($uid)
 {
     return zend_shm_cache_fetch($uid);
 }
Example #19
0
function Aspis_create_function($params, $code)
{
    global $ASPIS_PIPE_SEND;
    global $ASPIS_PIPE_RECEIVE;
    global $ASPIS_CATEGORIES_FILE;
    //is it there in the cache?
    if (isset($_SERVER[0]['HTTP_USER_AGENT'])) {
        $dynamic_functions = zend_shm_cache_fetch('wp_dynamic_functions');
        if ($dynamic_functions !== false) {
            if (isset($dynamic_functions[$code[0]]) && !empty($dynamic_functions[$code[0]])) {
                //                echo "Dynamic function <br>$code[0]<br> is in cache!<br>";
                return create_function($params[0], $dynamic_functions[$code[0]]);
            }
        }
    }
    $r = posix_mkfifo($ASPIS_PIPE_SEND, 0777);
    if (!$r) {
        unlink($ASPIS_PIPE_SEND);
        $r = posix_mkfifo($ASPIS_PIPE_SEND, 0777);
        if (!$r) {
            die("Could not create pipe {$ASPIS_PIPE_SEND}\n");
        }
    }
    $r = posix_mkfifo($ASPIS_PIPE_RECEIVE, 0777);
    if (!$r) {
        unlink($ASPIS_PIPE_RECEIVE);
        $r = posix_mkfifo($ASPIS_PIPE_RECEIVE, 0777);
        if (!$r) {
            die("Could not create pipe {$ASPIS_PIPE_RECEIVE}\n");
        }
    }
    if (!$r) {
        die("Could not create pipe {$ASPIS_PIPE}\n");
    }
    exec("aspis -in {$ASPIS_PIPE_SEND} -out {$ASPIS_PIPE_RECEIVE} -categories {$ASPIS_CATEGORIES_FILE} -mode online >/dev/null &", $a);
    $handle_send = fopen($ASPIS_PIPE_SEND, 'w');
    fwrite($handle_send, "<?php " . $code[0]);
    fclose($handle_send);
    $a = file($ASPIS_PIPE_RECEIVE);
    array_shift($a);
    unlink($ASPIS_PIPE_SEND);
    unlink($ASPIS_PIPE_RECEIVE);
    $rewritten = implode($a);
    //store it to the cache
    if (isset($_SERVER[0]['HTTP_USER_AGENT'])) {
        $dynamic_functions = zend_shm_cache_fetch('wp_dynamic_functions');
        //        echo "Storing rewritten version: $rewritten<br>";
        if ($dynamic_functions !== false) {
            $dynamic_functions[$code[0]] = $rewritten;
            zend_shm_cache_store('wp_dynamic_functions', $dynamic_functions, 24 * 3600);
        } else {
            $dynamic_functions = array($code[0] => $rewritten);
            zend_shm_cache_store('wp_dynamic_functions', $dynamic_functions, 24 * 3600);
        }
    }
    return array(create_function($params[0], $rewritten), false);
}
 protected function getValue($key)
 {
     return zend_shm_cache_fetch($key);
 }
 function pmxCacheGet($key, $useMember = false, $null_array = false)
 {
     global $PortaMx_cache, $user_info;
     $st = microtime(true);
     $key = $PortaMx_cache['key'] . ($useMember ? '-' . implode('_', $user_info['groups']) : '') . '-' . $key;
     if (function_exists('zend_shm_cache_fetch')) {
         $value = zend_shm_cache_fetch('PMX::' . $key);
     } elseif (function_exists('output_cache_get')) {
         $value = output_cache_get($key, $ttl);
     }
     if (!empty($value)) {
         $PortaMx_cache['vals']['loaded'] += strlen($value);
         $PortaMx_cache['vals']['time'] += microtime(true) - $st;
         return unserialize($value);
     }
     $PortaMx_cache['vals']['time'] += microtime(true) - $st;
     return empty($null_array) ? null : array();
 }
Example #22
0
 /**
  * Fetch data
  *
  * @param string $id          Cache id
  */
 protected function _fetch($id)
 {
     return zend_shm_cache_fetch($this->_options['namespace'] . '::' . $id);
 }
Example #23
0
function load_taint_categories()
{
    global $taint_categories;
    $read_file = true;
    if (isset($_SERVER[0]['HTTP_USER_AGENT'])) {
        $taint_categories = zend_shm_cache_fetch('taint_categories');
        if ($taint_categories !== false) {
            $read_file = false;
        }
    }
    if ($read_file) {
        global $ASPIS_CATEGORIES_FILE;
        $file = file($ASPIS_CATEGORIES_FILE, FILE_USE_INCLUDE_PATH | FILE_IGNORE_NEW_LINES);
        for ($i = 0; $i < count($file); $i++) {
            $line = $file[$i];
            if ($line == "begin") {
                $tc = array(array(), array());
                $reading_sanitisation = 0;
                $reading_sinks = 0;
                $reading_sources = 0;
                while (1) {
                    $line = $file[++$i];
                    if ($line == "end") {
                        break;
                    } else {
                        if ($line == ">sanitisation") {
                            $reading_sanitisation = 1;
                            continue;
                        } else {
                            if ($line == ">sinks") {
                                $reading_sanitisation = 0;
                                $reading_sinks = 1;
                                continue;
                            } else {
                                if ($line == ">sources") {
                                    $reading_sanitisation = 0;
                                    $reading_sinks = 0;
                                    $reading_sources = 1;
                                    continue;
                                }
                            }
                        }
                    }
                    if ($reading_sanitisation) {
                        $tc[0][$line] = 1;
                    } else {
                        if ($reading_sinks || $reading_sources) {
                            $tok1 = strtok($line, "->");
                            $tok2 = strtok("->");
                            if ($tok1 != "" && $tok2 != "") {
                                if ($reading_sinks) {
                                    $tc[1][$tok1] = $tok2;
                                } else {
                                    if ($reading_sources) {
                                        $tc[2][$tok1] = $tok2;
                                    }
                                }
                            } else {
                                die("Invalid guard in the category file");
                            }
                        }
                    }
                }
                $taint_categories[] = $tc;
            }
        }
        if (isset($_SERVER[0]['HTTP_USER_AGENT'])) {
            zend_shm_cache_store('taint_categories', $taint_categories, 24 * 3600);
        }
    }
}