function ver($id) { redirect(site_url('fichas/ver/' . $id), 'location', 301); if (!($data = apc_fetch('movil_fichas_ver_data' . $id))) { $data['theme_page'] = "d"; $data['theme_header'] = "a"; $ficha = Doctrine::getTable('Ficha')->findPublicado($id); if ($ficha[0]->titulo) { $data['title'] = $ficha[0]->titulo; if ($ficha[0]->flujo) { $data['content'] = 'movil/verflujo'; } else { $data['content'] = 'movil/verficha'; } $data['vista_ficha'] = true; $data['ficha'] = $ficha[0]; if ($this->config->item('cache')) { apc_store('movil_fichas_ver_data' . $id, $data, 60 * $this->config->item('cache')); } } else { redirect('movil/ficha/error/'); } } $this->load->view('movil/template', $data); }
/** * 写入缓存 * @access public * @param string $name 缓存变量名 * @param mixed $value 存储数据 * @param integer $expire 有效时间(秒) * @return bool */ public function set($name, $value, $expire = null) { if (is_null($expire)) { $expire = $this->options['expire']; } $name = $this->options['prefix'] . $name; if ($result = apc_store($name, $value, $expire)) { if ($this->options['length'] > 0) { // 记录缓存队列 $queue = apc_fetch('__info__'); if (!$queue) { $queue = []; } if (false === array_search($name, $queue)) { array_push($queue, $name); } if (count($queue) > $this->options['length']) { // 出列 $key = array_shift($queue); // 删除缓存 apc_delete($key); } apc_store('__info__', $queue); } } return $result; }
/** gets a value * * @param string * @param mixed string or array of string * * @return mixed the value from fastDS **/ protected function getValue($prefix, $keys) { $success = null; if (is_array($keys)) { $apcKeys = array(); foreach ($keys as $key) { if (is_string($key)) { $apcKeys[$key] = $this->prefix . $prefix . $key; } } $apc = apc_fetch($apcKeys, $success); if (!$success) { return false; } $result = array(); foreach ($apcKeys as $key => $apcKey) { if (isset($apc[$apcKey])) { $result[$key] = $apc[$apcKey]; } } return $result; } $apc = apc_fetch($this->prefix . $prefix . $keys, $success); if ($success) { return $apc; } return false; }
/** * @param string $ClassName * * @return bool */ public function loadClass($ClassName) { if ($this->checkExists($ClassName)) { return true; } if (function_exists('apc_fetch')) { $Hash = sha1($this->Namespace . $this->Path . $this->Separator . $this->Extension . $this->Prefix); // @codeCoverageIgnoreStart if (false === ($Result = apc_fetch($Hash . '#' . $ClassName))) { $Result = $this->checkCanLoadClass($ClassName); apc_store($Hash . '#' . $ClassName, $Result ? 1 : 0); } if (!$Result) { return false; } } else { // @codeCoverageIgnoreEnd if (!$this->checkCanLoadClass($ClassName)) { return false; } } /** @noinspection PhpIncludeInspection */ require $this->Path . DIRECTORY_SEPARATOR . trim(str_replace(array($this->Prefix . $this->Separator, $this->Separator), array('', DIRECTORY_SEPARATOR), $ClassName), DIRECTORY_SEPARATOR) . $this->Extension; return $this->checkExists($ClassName); }
function query($type) { if (!is_null($type)) { //get parameter data $parameters = Flight::request()->query->getData(); $cacheKey = $type . json_encode($parameters); if (apc_exists($cacheKey)) { echo apc_fetch($cacheKey); } else { $url = 'http://localhost:8080/sparql'; $query_string = file_get_contents('queries/' . $type . '.txt'); foreach ($parameters as $key => $value) { $query_string = str_replace('{' . $key . '}', $value, $query_string); } //open connection $ch = curl_init(); //set the url, number of POST vars, POST data curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/sparql-query")); curl_setopt($ch, CURLOPT_POSTFIELDS, $query_string); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); //execute post $result = curl_exec($ch); //close connection curl_close($ch); apc_store($cacheKey, $result); echo $result; } } }
public function __construct($table, $field, $min, $condition = "", $cacheName = "") { if (empty($cacheName) || $cacheName == "") { $cacheName = $table; } $this->array = apc_fetch($cacheName, $success); if (!$success) { echo "{$table} FROM DATABASE"; if (!empty($condition)) { echo $query = "select {$field} from {$table} where {$condition} order by {$field}"; } else { echo $query = "select {$field} from {$table} order by {$field}"; } $result = mysql_query($query) or trigger_error(mysql_error(), E_USER_ERROR); if (mysql_num_rows($result)) { echo "Sucess"; $this->array = array(); while ($row = mysql_fetch_array($result)) { $this->array[] = strtolower($row[$field]); } apc_store($cacheName, $this->array); } } $this->count = count($this->array); $this->min = $min; }
/** * Logs the number of milliseconds till this named point. */ public static function profile($point) { if (!self::$profilingEnabled) { return; } $path = ""; if (isset($_SERVER['REQUEST_URI'])) { $path = $_SERVER['REQUEST_URI']; } if (strpos($path, 'af_format=json') !== false) { $memory = apc_fetch('Console::memory'); if ($memory !== false) { list(self::$startedAt, self::$last) = $memory; } } $now = microtime(true); if (self::$startedAt === null) { self::$startedAt = $now; self::$last = $now; } $totalMillis = ($now - self::$startedAt) * 1000; $passedMillis = ($now - self::$last) * 1000; file_put_contents('php://stderr', self::formatPoint($totalMillis, $passedMillis, $point, $path)); self::$last = $now; apc_store('Console::memory', array(self::$startedAt, self::$last)); }
function get_sensor_name_list () { $sensor_list = apc_fetch('sensor_list'); //var_dump($sensor_list); if (!$sensor_list) // if not available in APC then read the list from DB, then save the list in APC { //echo "must read sesnor list from db"; $static_db = open_static_data_db(true); $results = $static_db->query('SELECT * FROM sensor_names;'); while ($row = $results->fetchArray()) { $sensor_id = $row['id']; $sensor_name = $row['sensor_name']; $sensor_list[$sensor_id] = $sensor_name; //var_dump($sensor_list); // save the sensor list in APC } $static_db->close(); apc_store('sensor_list', $sensor_list); } return $sensor_list; }
function getClassPath() { static $classpath = array(); if (!empty($classpath)) { return $classpath; } if (function_exists("apc_fetch")) { $classpath = apc_fetch("fw:root:autoload:map:1397705849"); if ($classpath) { return $classpath; } $classpath = getClassMapDef(); apc_store("fw:root:autoload:map:1397705849", $classpath); } else { if (function_exists("eaccelerator_get")) { $classpath = eaccelerator_get("fw:root:autoload:map:1397705849"); if ($classpath) { return $classpath; } $classpath = getClassMapDef(); eaccelerator_put("fw:root:autoload:map:1397705849", $classpath); } else { $classpath = getClassMapDef(); } } return $classpath; }
/** * Returns the ACL list * * @return Phalcon\Acl\Adapter\Memory */ public function getAcl() { // Check if the ACL is already created if (is_object($this->acl)) { return $this->acl; } // Check if the ACL is in APC if (function_exists('apc_fetch')) { $acl = apc_fetch('vokuro-acl'); if (is_object($acl)) { $this->acl = $acl; return $acl; } } // Check if the ACL is already generated if (!file_exists(APP_DIR . $this->filePath)) { $this->acl = $this->rebuild(); return $this->acl; } // Get the ACL from the data file $data = file_get_contents(APP_DIR . $this->filePath); $this->acl = unserialize($data); // Store the ACL in APC if (function_exists('apc_store')) { apc_store('vokuro-acl', $this->acl); } return $this->acl; }
/** * Finds a file by class name while caching lookups to APC. * * @param string $class A class name to resolve to file * * @return string|null The path, if found */ public function findFile($class) { if (false === ($file = apc_fetch($this->prefix . $class))) { apc_store($this->prefix . $class, $file = parent::findFile($class)); } return $file; }
function loguear($is_cache) { global $link, $original_req, $log_active; if ($log_active) { $cache_key2 = "IPsLog"; $cache = apc_fetch($cache_key2, $susses); $link_log = $original_req; if ($original_req != $link) { $link_log = $original_req . " -> " . $link; } if ($is_cache) { $link_log = "(from cache)" . $link_log; } $add = "(IP: " . $_SERVER['REMOTE_ADDR'] . ") " . $link_log . "\n [header: " . getallheaders() . "]"; if ($susses) { apc_store($cache_key2, $cache . "\n\n" . $add, 1800); } else { apc_store($cache_key2, $add, 1800); } $cache_key2 = "IPsLogExcel"; $cache = apc_fetch($cache_key2, $susses); $add = $_SERVER['REMOTE_ADDR'] . "\t" . $original_req . "\t" . $link . "\t" . $_SERVER['HTTP_REFERER'] . "\n"; if ($susses) { apc_store($cache_key2, $cache . $add, 1800); } else { $add = "IP\tOriginal request\tRequest Procesado\tReferer\n" . $add; apc_store($cache_key2, $add, 1800); } } }
/** * Clean the cache. If group is specified, clean only the group */ public function clean($group = null, $mode = 'group') { if (!$this->_caching) { return; } if (!is_null($group)) { $tags = apc_fetch('jomsocial-tags'); if (is_null($tags)) { apc_clear_cache('user'); $tags = array(); } // @todo: for each cache id, we should clear it from other tag list as well foreach ($group as $tag) { if (!empty($tags[$tag])) { foreach ($tags[$tag] as $id) { apc_delete($id); } } } } else { // Clear everything apc_clear_cache('user'); } return true; }
function getDurationMillis($filePath) { global $ffprobeBin; // try to fetch from cache $cacheKey = "duration-{$filePath}"; $duration = apc_fetch($cacheKey); if ($duration) { return $duration; } // execute ffprobe $commandLine = "{$ffprobeBin} -i {$filePath} -show_streams -print_format json -v quiet"; $output = null; exec($commandLine, $output); // parse the result - take the shortest duration $ffmpegResult = json_decode(implode("\n", $output)); $duration = null; foreach ($ffmpegResult->streams as $stream) { $curDuration = floor(floatval($stream->duration) * 1000); if (is_null($duration) || $curDuration < $duration) { $duration = $curDuration; } } // store to cache apc_store($cacheKey, $duration); return $duration; }
public static function get($key) { global $config, $debug; $key = $config['cache']['prefix'] . $key; $data = false; switch ($config['cache']['enabled']) { case 'memcached': if (!self::$cache) { self::init(); } $data = self::$cache->get($key); break; case 'apc': $data = apc_fetch($key); break; case 'xcache': $data = xcache_get($key); break; case 'php': $data = isset(self::$cache[$key]) ? self::$cache[$key] : false; break; } // debug if ($data && $config['debug']) { $debug['cached'][] = $key; } return $data; }
function ApcCheckIp($installer) { $ok = true; $ip = $_SERVER["REMOTE_ADDR"]; if (isset($ip) && strlen($ip)) { $now = time(); $key = "inst-ip-{$ip}-{$installer}"; $history = apc_fetch($key); if (!$history) { $history = array(); } elseif (!is_array($history)) { $history = json_decode($history, true); if (!$history) { $history = array(); } } $history[] = $now; // Use 1KB blocks to prevent fragmentation apc_store($key, str_pad(json_encode($history), 1000), 604800); if (count($history) > 10) { array_shift($history); } $count = 0; foreach ($history as $time) { if ($now - $time < 3600) { $count++; } } if ($count > 4) { $ok = false; } } return $ok; }
public static function get($key = '') { if (self::dataStoreAvailable()) { $value = apc_fetch($key); return $value; } }
/** * Get cache for $name if exist. * * @param string $name Cache id * * @return mixed data on hit, boolean false on cache not found */ public function get($name) { if (apc_exists($name)) { return apc_fetch($name); } return false; }
/** * Retrieve the value corresponding to a provided key * * @param string $key Unique identifier * @return mixed Result from the cache */ public function get($key) { if (!$this->safe) { return false; } return apc_fetch($key); }
function phorum_cache_get($type, $key, $version = NULL) { if (is_array($key)) { $ret = array(); foreach ($key as $realkey) { $getkey = $type . "_" . $realkey; $data = apc_fetch($getkey); if ($data !== false) { if ($version == NULL || $data[1] != NULL && $data[1] == $version) { $ret[$realkey] = $data[0]; } } } } else { $getkey = $type . "_" . $key; $data = apc_fetch($getkey); if ($data !== false) { if ($version == NULL || $data[1] != NULL && $data[1] == $version) { $ret = $data[0]; } } else { $ret = false; } } if ($ret === false || is_array($ret) && count($ret) == 0) { $ret = NULL; } return $ret; }
public static function getIdByStrId($strId) { // try to get strId to id mapping form cache $cacheKey = 'UserRolePeer_role_str_id_' . $strId; if (kConf::get('enable_cache') && function_exists('apc_fetch') && function_exists('apc_store')) { $id = apc_fetch($cacheKey); // try to fetch from cache if ($id) { KalturaLog::debug("UserRole str_id [{$strId}] mapped to id [{$id}] - fetched from cache"); return $id; } } // not found in cache - get from database $c = new Criteria(); $c->addSelectColumn(UserRolePeer::ID); $c->addAnd(UserRolePeer::STR_ID, $strId, Criteria::EQUAL); $c->setLimit(1); $stmt = UserRolePeer::doSelectStmt($c); $id = $stmt->fetch(PDO::FETCH_COLUMN); if ($id) { // store the found id in cache for later use if (kConf::get('enable_cache') && function_exists('apc_fetch') && function_exists('apc_store')) { $success = apc_store($cacheKey, $id, kConf::get('apc_cache_ttl')); if ($success) { KalturaLog::debug("UserRole str_id [{$strId}] mapped to id [{$id}] - stored in cache"); } } } if (!$id) { KalturaLog::log("UserRole with str_id [{$strId}] not found in DB!"); } return $id; }
public function getPosition($userid, $aaID) { $detais = apc_fetch("fs_" . $userid . "_" . $aaID); $detais["track"] = intval($detais["track"]); $detais["position"] = intval($detais["position"]); return $detais; }
function __jax__loadClass($class_name) { global $__CLASS_AUTO_LOAD_CLASS_PATHS, $__CLASS_AUTO_LOAD_PATH_CACHE_TIMEOUT; $cacheKey = 'classAutoload:' . sha1($_SERVER['DOCUMENT_ROOT']) . ':' . $class_name; if (function_exists('apc_fetch')) { $path = @apc_fetch($cacheKey, $success); } else { $path = null; $success = false; } if (!$success) { foreach ($__CLASS_AUTO_LOAD_CLASS_PATHS as $dir) { $path = __jax__classAutoloadFindClassFile($class_name, $dir); if ($path !== false) { if (function_exists('apc_add')) { @apc_add($cacheKey, $path, $__CLASS_AUTO_LOAD_PATH_CACHE_TIMEOUT); } else { if (function_exists('apc_store')) { @apc_store($cacheKey, $path, $__CLASS_AUTO_LOAD_PATH_CACHE_TIMEOUT); } } break; } } } if ($path !== false) { include $path; } }
/** * Get * * Since this is the dummy class, it's always going to return FALSE. * * @param string * @return Boolean FALSE */ public function readCache($type, $name, $ID, $onlyCheck = FALSE) { $this->getInstance(); $originalID = $ID; if (isset($_POST) && count($_POST) > 0) { $ID = $ID . md5(serialize($_POST)); } self::logMessage('cache', "Reading APC {$type} - {$name} - {$ID}."); $item_expiration = $this->getCacheItemExpiration($type, $name, $originalID); if (is_array($item_expiration)) { $item_properties = $item_expiration; $name .= '-' . $item_properties[0]; $item_expiration = $item_properties[1]; } if ($item_expiration == FALSE) { $item_expiration = $this->getCacheConfigItem('default', $type); if ($item_expiration == FALSE) { return FALSE; } } $cache = apc_fetch($type . '-' . $name . '-' . $ID); if ($cache == FALSE) { return FALSE; } self::logMessage('cache', 'APC Read OK: ' . $type . '/' . $name . '/' . $ID); if ($cache && $onlyCheck) { return TRUE; } return unserialize($cache); }
/** * Returns upload status. * * This is implementation for APC extension. * * @param string $id * * @return array|null */ function PMA_getUploadStatus($id) { global $SESSION_KEY; global $ID_KEY; if (trim($id) == "") { return null; } if (!array_key_exists($id, $_SESSION[$SESSION_KEY])) { $_SESSION[$SESSION_KEY][$id] = array('id' => $id, 'finished' => false, 'percent' => 0, 'total' => 0, 'complete' => 0, 'plugin' => $ID_KEY); } $ret = $_SESSION[$SESSION_KEY][$id]; if (!PMA_import_apcCheck() || $ret['finished']) { return $ret; } $status = apc_fetch('upload_' . $id); if ($status) { $ret['finished'] = (bool) $status['done']; $ret['total'] = $status['total']; $ret['complete'] = $status['current']; if ($ret['total'] > 0) { $ret['percent'] = $ret['complete'] / $ret['total'] * 100; } if ($ret['percent'] == 100) { $ret['finished'] = (bool) true; } $_SESSION[$SESSION_KEY][$id] = $ret; } return $ret; }
/** * {@inheritdoc} */ public function info($key) { if (!($content = apc_fetch($key))) { return false; } return unserialize($content); }
public function testConstructor() { $loader = new ApcUniversalClassLoader('test.prefix.'); $loader->registerNamespace('Apc\Namespaced', __DIR__.DIRECTORY_SEPARATOR.'Fixtures'); $this->assertEquals($loader->findFile('\Apc\Namespaced\FooBar'), apc_fetch('test.prefix.\Apc\Namespaced\FooBar'), '__construct() takes a prefix as its first argument'); }
/** * Retrieve an object from the cache. * * @param string $type * A name for the group of data that is being cached. * Examples are "user" and "message". * * @param string|array $key * A unique key that identifies the object to retrieve. * This could for example be the user_id of a cached user. * This can also be an array of keys. * * @param integer $version * The version of the object to retrieve. If the cached object's * version is older than the requested version, then no object * will be returned. * * @return mixed * This function returns the cached object for the given key * or NULL if no data is cached or if the cached data has expired. * * When an array of keys is provided in the $key argument, then * an array will be returned. The keys in this array are the cache keys * for which cached data is available. If no cached data is available * for any of the keys, then NULL is returned. */ function phorum_api_cache_get($type, $key, $version = NULL) { global $PHORUM; $sepkey = $PHORUM['CACHECONFIG']['separation_key']; if (is_array($key)) { $ret = array(); foreach ($key as $realkey) { $realkey = md5($sepkey . $realkey); $getkey = $type . "_" . $realkey; $data = apc_fetch($getkey); if ($data !== FALSE) { if ($version == NULL || $data[1] != NULL && $data[1] == $version) { $ret[$realkey] = $data[0]; } } } } else { $key = md5($sepkey . $key); $getkey = $type . "_" . $key; $data = apc_fetch($getkey); if ($data !== FALSE) { if ($version == NULL || $data[1] != NULL && $data[1] == $version) { $ret = $data[0]; } } else { $ret = FALSE; } } if ($ret === FALSE || is_array($ret) && count($ret) == 0) { $ret = NULL; } return $ret; }
/** * @see wcf\system\cache\source\ICacheSource::get() */ public function get($cacheName, $maxLifetime) { if (($data = apc_fetch($this->prefix . $cacheName)) === false) { return null; } return $data; }
function pdfToString() { $weekNumber = date('W'); //Check if we have the current week in cache $text = apc_fetch('hungertext' . $weekNumber); if ($text !== false) { return $text; } //Otherwise fetch all links $links = crawl_page(URL_PAGE_WITH_LINKS); $pdfLink = ''; foreach ($links as $file) { if (strpos(strtolower($file), '.pdf') !== FALSE && strpos($file, '_FMI_') !== FALSE && $weekNumber === substr($file, 16, 2)) { $pdfLink = URL_MAIN . $file; } } //Don't proceed when no link was found if (empty($pdfLink)) { return; } // Parse pdf file and build necessary objects. $parser = new \Smalot\PdfParser\Parser(); $pdf = $parser->parseFile($pdfLink); $text = $pdf->getText(); //Store it in cache apc_store('hungertext' . $weekNumber, $text, 2 * 24 * 3600); //return it return $text; }