/** * Return Http Response object for a given url. */ public function getResponse($url) { try { $response = $this->http_client->get($url, array('headers' => $this->getRequestHeaders())); if (empty($response)) { throw new MigrateException('No response at ' . $this->getPath() . '.'); } } catch (RequestException $e) { throw new MigrateException('Error message: ' . $e->getMessage() . ' at ' . $url . '.'); $response = NULL; } return $response; }
/** * 获取缓存 * @param string $key 缓存键 * @param int $lockTime 缓存锁失效时间 * @return mixed */ public function get($key, $lockTime = 3) { $key = DAGGER_MC_KEY_PREFIX . $key; if ($this->snowslide) { $outdated = $this->mc->get($key . self::CACHE_TIME_CTL); $data = $this->mc->get($key); if ($data === false || $outdated === false || isset($_GET['_flush_cache']) && $_GET['_flush_cache'] == 1) { if ($this->getLock($key, $lockTime)) { defined('DAGGER_DEBUG') && BaseModelCommon::debug(false, "mc_get_not_lock({$key})"); return false; } $attempt = 0; do { $dataNew = $this->mc->get($key); if (++$attempt >= 4) { break; } if ($dataNew === false) { usleep(100000); } else { return $dataNew; } } while ($data === false); } } else { $data = $this->mc->get($key); } defined('DAGGER_DEBUG') && BaseModelCommon::debug($data, "mc_get({$key})"); return $data; }
/** * This function will download a file from the ftp-server. * * @access public * @param string $remote_file The absolute or relative path to the file to download * @param string $local_file The local file to put the downloaded in * @param bool $overwrite (optional) Whether to overwrite existing file * @param int $mode (optional) Either FTP_ASCII or FTP_BINARY * @return mixed True on success, otherwise Jaws_Error */ function get($remote_file, $local_file, $overwrite = false, $mode = null) { $res = $this->_ftp->get($remote_file, $local_file, $overwrite, $mode); if (PEAR::isError($res)) { return new Jaws_Error($res->getMessage(), __FUNCTION__); } return true; }
/** * Returns the data from the cache associated with key $key. * * @param mixed $key * @return mixed */ public function fetch($key) { if (strlen($key) > self::MAX_KEY_LENGTH) { throw new ezcCacheInvalidKeyException($key, 'Length > ' . self::MAX_KEY_LENGTH . '.'); } $data = $this->memcache->get($key); return is_object($data) ? $data->var : false; }
/** * 读取缓存,使用pecl-memcached * * @param mixed $keys * @access protected * @return mixed */ protected function _getMemcached($keys) { if (is_array($keys)) { return $this->_conn->getMulti($keys); } else { return $this->_conn->get($keys); } }
/** * Writes session data to the memcache based session storage handler * * @param string $id The ID of the session * @param string $value The session data to store * @access protected */ protected function _write($id, $value) { $id = 'sess_' . $id; if ($this->_conn->get($id)) { return $this->_conn->replace($id, $value, 0, $this->_life_time); } else { return $this->_conn->set($id, $value, 0, $this->_life_time); } }
/** * get * @param string $key * @param string $tableName * @param resource $connectionResource * @return boolean */ public function get($key, $tableName, $connectionResource) { $cachedArray = $connectionResource->get($this->getRealKey($tableName, $key)); if (is_array($cachedArray) && (0 == $cachedArray["ttl"] || $cachedArray["ttl"] > time())) { return $cachedArray["value"]; } else { return false; } }
/** * Read * * Reads session data and acquires a lock * * @param string $session_id Session ID * @return string Serialized session data */ public function read($session_id) { if (isset($this->_redis) && $this->_get_lock($session_id)) { // Needed by write() to detect session_regenerate_id() calls $this->_session_id = $session_id; $session_data = (string) $this->_redis->get($this->_key_prefix . $session_id); $this->_fingerprint = md5($session_data); return $session_data; } return $this->_failure; }
/** * Read * * Reads session data and acquires a lock * * @param string $session_id Session ID * @return string Serialized session data */ public function read($session_id) { if (isset($this->redis) && $this->lockSession($session_id)) { // Needed by write() to detect session_regenerate_id() calls $this->_session_id = $session_id; $session_data = (string) $this->redis->get($this->keyPrefix . $session_id); $this->_fingerprint = md5($session_data); return $session_data; } return FALSE; }
/** * Set expire time on each call since memcache sets it on cache creation. * * @access private * * @param string $key Cache key to expire. * @param integer $lifetime Lifetime of the data in seconds. */ function _setExpire($key) { $lifetime = $this->_lifetime; $expire = $this->_db->get($key . '_expire'); // set prune period if ($expire + $lifetime < time()) { $this->_db->delete($key); $this->_db->delete($key . '_expire'); } else { $this->_db->replace($key . '_expire', time()); } }
/** * Set expire time on each call since memcached sets it on cache creation. * * @param string $key Cache key to expire. * * @return void * * @since 11.1 */ protected function _setExpire($key) { $lifetime = ini_get("session.gc_maxlifetime"); $expire = $this->_db->get($key . '_expire'); // Set prune period if ($expire + $lifetime < time()) { $this->_db->delete($key); $this->_db->delete($key . '_expire'); } else { $this->_db->replace($key . '_expire', time()); } }
/** * @param string $remotePath * @param string $destFile * @param int $resumePos * * @return bool */ public function get($remotePath, $destFile, $resumePos = 0) { switch ($this->_connType) { case SftpHelper::TYPE_SFTP: default: $res = $this->_connection->get($remotePath, $destFile, $resumePos); break; case SftpHelper::TYPE_FTP: $res = @ftp_get($this->_connection, $destFile, $remotePath, FTP_BINARY, $resumePos); break; } return $res; }
function exception(Exception $e) { if (ob_get_length() != false) { @ob_end_clean(); } $et = typeOf($e); if ($et == 'FileNotFoundException' || $et == 'NavigationException') { response::setStatus(404); header('HTTP/1.1 404 Not Found', true); printf("<h1>404: Not Found</h1>"); return; } if ($et == 'HttpException') { response::setStatus($e->getCode()); $code = $e->getMessage(); list($code) = explode(':', $code); $code = str_replace('Error ', '', $code); $msg = HttpException::getHttpMessage($code); header('HTTP/1.1 ' . $code . ' ' . $msg . ' ' . $msg); printf("<h1>%s: %s</h1>\n<pre>%s</pre>", $code, $msg, $msg); return; } response::setStatus(500); logger::emerg("Unhandled exception: (%s) %s in %s:%d", get_class($e), $e->getMessage(), str_replace(BASE_PATH, '', $e->getFile()), $e->getLine()); header('HTTP/1.1 501 Server Error', true); $id = uniqid(); $dbg = sprintf("Unhandled exception: (%s) %s\n in %s:%d", get_class($e), $e->getMessage(), str_replace(SYS_PATH, '', $e->getFile()), $e->getLine()) . Console::backtrace(0, $e->getTrace(), true) . "\n" . "Loaded modules:\n" . ModuleManager::debug() . "\n" . request::getDebugInformation(); logger::emerg($dbg); if (config::get('lepton.mvc.exception.log', false) == true) { $logfile = config::get('lepton.mvc.exception.logfile', "/tmp/" . $_SERVER['HTTP_HOST'] . "-debug.log"); $log = "=== Unhandled Exception ===\n\n" . $dbg . "\n"; $lf = @fopen($logfile, "a+"); if ($lf) { fputs($lf, $log); fclose($lf); } } $ico_error = resource::get('warning.png'); header('content-type: text/html; charset=utf-8'); echo '<html><head><title>Unhandled Exception</title>' . self::$css . self::$js . '</head><body>' . '<div id="box"><div id="left"><img src="' . $ico_error . '" width="32" height="32"></div><div id="main">' . '<h1>An Unhandled Exception Occured</h1>' . '<hr noshade>' . '<p>This means that something didn\'t go quite go as planned. This could be ' . 'caused by one of several reasons, so please be patient and try ' . 'again in a little while.</p>'; if (config::get('lepton.mvc.exception.feedback', false) == true) { echo '<p>The administrator of the website has been notified about this error. You ' . 'can help us find and fix the problem by writing a line or two about what you were doing when this ' . 'error occured.</p>'; echo '<p id="feedbacklink"><a href="javascript:doFeedback();">If you would like to assist us with more information, please click here</a>.</p>'; echo '<div id="feedback" style="display:none;"><p>Describe in a few short lines what you were doing right before you encountered this error:</p><form action="/errorevent.feedback/' . $id . '" method="post"><div><textarea name="text" style="width:100%; height:50px;"></textarea></div><div style="padding-top:5px; text-align:right;"><input type="button" value=" Close " onclick="closeFeedback();"> <input type="submit" value=" Submit Feedback "></div></form></div>'; } if (config::get('lepton.mvc.exception.showdebug', false) == true) { echo '<hr noshade>' . '<a href="javascript:toggleAdvanced();">Details »</a>' . '<pre id="advanced" style="display:none; height:300px;">' . $dbg . '</pre>'; } echo '<div>' . '</body></html>'; }
/** * 指定服务器自减 * @param string $server_key 服务器标识 * @param string $key 缓存键 * @param int $incre 自减值 * @return int */ public function decrement($key, $incre = 1) { $this->startRunTime = microtime(true); $calls = 1; if ($this->native) { $ret = $this->mcd->decrement($key, $incre); } else { $ret = $this->mcd->get($this->_buildKey($key, 'TIME_CTL')); if ($this->mcd->getResultCode() === Memcached::RES_SUCCESS) { $ret = $this->mcd->decrement($key, $incre); $calls++; } $this->lastResultCode = $this->mcd->getResultCode(); $this->lastResultMessage = $this->mcd->getResultMessage(); } $this->_checkStats(__FUNCTION__, $calls); defined('DAGGER_DEBUG') && BaseModelCommon::debug($ret, "mcd_decrement({$key})"); return $ret; }
/** * Clean cache for a group given a mode. * * group mode : cleans all cache in the group * notgroup mode : cleans all cache not in the group * * @access public * @param string $group The cache data group * @param string $mode The mode for cleaning cache [group|notgroup] * @return boolean True on success, false otherwise * @since 1.5 */ function clean($group, $mode) { if (!$this->lockindex()) { return false; } $index = $this->_db->get($this->_hash . '-index'); if ($index === false) { $index = array(); } $secret = $this->_hash; foreach ($index as $key => $value) { if (strpos($value->name, $secret . '-cache-' . $group . '-' . $this->_site) === 0 xor $mode != 'group') { $this->_db->delete($value->name, 0); unset($index[$key]); } } $this->_db->replace($this->_hash . '-index', $index, 0, 0); $this->unlockindex(); return true; }
/** * Clone the cell collection * * @param PHPExcel_Worksheet $parent The new worksheet * @return void */ public function copyCellCollection(PHPExcel_Worksheet $parent) { parent::copyCellCollection($parent); // Get a new id for the new file name $baseUnique = $this->_getUniqueID(); $newCachePrefix = substr(md5($baseUnique), 0, 8) . '.'; $cacheList = $this->getCellList(); foreach ($cacheList as $cellID) { if ($cellID != $this->_currentObjectID) { $obj = $this->_memcache->get($this->_cachePrefix . $cellID . '.cache'); if ($obj === false) { // Entry no longer exists in Memcache, so clear it from the cache array parent::deleteCacheData($cellID); throw new PHPExcel_Exception('Cell entry ' . $cellID . ' no longer exists in MemCache'); } if (!$this->_memcache->add($newCachePrefix . $cellID . '.cache', $obj, NULL, $this->_cacheTime)) { $this->__destruct(); throw new PHPExcel_Exception('Failed to store cell ' . $cellID . ' in MemCache'); } } } $this->_cachePrefix = $newCachePrefix; }
/** * Compare revisions and returns array of files to upload: * * array( * 'upload' => $filesToUpload, * 'delete' => $filesToDelete * ); * * @param string $localRevision * @return array * @throws Exception if unknown git diff status */ public function compare($localRevision) { $remoteRevision = null; $tmpFile = tmpfile(); $filesToUpload = array(); $filesToDelete = array(); $filesToSkip = array(); $output = array(); if ($this->currentSubmoduleName) { $this->dotRevision = $this->currentSubmoduleName . '/' . $this->dotRevisionFilename; } else { $this->dotRevision = $this->dotRevisionFilename; } // Fetch the .revision file from the server and write it to $tmpFile $this->debug("Fetching {$this->dotRevision} file"); if ($this->connection->exists($this->dotRevision)) { $remoteRevision = $this->connection->get($this->dotRevision); } else { $this->output('<yellow>|----[ No revision found. Fresh deployment - grab a coffee ]----|'); } // Use git to list the changed files between $remoteRevision and $localRevision // "-c core.quotepath=false" in command fixes special chars issue like ë, ä or ü in file names if ($this->others) { $command = '-c core.quotepath=false ls-files -o'; } elseif (empty($remoteRevision)) { $command = '-c core.quotepath=false ls-files'; } elseif ($localRevision === 'HEAD') { $command = '-c core.quotepath=false diff --name-status ' . $remoteRevision . ' ' . $localRevision; } else { $command = '-c core.quotepath=false diff --name-status ' . $remoteRevision . ' ' . $localRevision; } $output = $this->gitCommand($command); /** * Git Status Codes * * A: addition of a file * C: copy of a file into a new one * D: deletion of a file * M: modification of the contents or mode of a file * R: renaming of a file * T: change in the type of the file * U: file is unmerged (you must complete the merge before it can be committed) * X: "unknown" change type (most probably a bug, please report it) */ if (!empty($remoteRevision) && !$this->others) { foreach ($output as $line) { if ($line[0] === 'A' or $line[0] === 'C' or $line[0] === 'M' or $line[0] === 'T') { $filesToUpload[] = trim(substr($line, 1)); } elseif ($line[0] == 'D' or $line[0] === 'T') { $filesToDelete[] = trim(substr($line, 1)); } else { throw new \Exception("Unsupported git-diff status: {$line[0]}"); } } } else { $filesToUpload = $output; } $filteredFilesToUpload = $this->filterIgnoredFiles($filesToUpload); $filteredFilesToDelete = $this->filterIgnoredFiles($filesToDelete); $filesToUpload = $filteredFilesToUpload['files']; $filesToDelete = $filteredFilesToDelete['files']; $filesToSkip = array_merge($filteredFilesToUpload['filesToSkip'], $filteredFilesToDelete['filesToSkip']); return array($this->currentlyDeploying => array('delete' => $filesToDelete, 'upload' => $filesToUpload, 'skip' => $filesToSkip)); }
/** * @param $key * * @return mixed */ function &get($key) { $key = $this->cleanKey($key); $result = $this->_cache->get($key); return $result; }
/** * Magic get item from registry * * @param mixed $key * @return mixed */ public function __get($key) { return $this->registry->get($key); }
function &get($key) { $result =& $this->_cache->get($key); return $result; }
/** * get * @param string $key * @param string $tableName * @param resource $connectionResource * @return string|array|object */ public function get($key, $tableName, $connectionResource) { return $connectionResource->get($this->getRealKey($tableName, $key)); }
/** * Get cached data from memcache by id and group * * @access public * @param string $id The cache data id * @param string $group The cache data group * @return mixed Boolean false on failure or a cached data string * @since 1.5 */ function get($id, $group = null) { $cache_id = $this->_getCacheId($id, $group); return $this->_db->get($cache_id); }
/** * Выполняет sql запрос. Плейсхолдеры НЕ обрабатывает. * * @param string $sql sql запрос или пустая строка если необходимо выполнить отложенные запросы * @param string $orig_sql исходная версия sql-запрос (с нераспарсенными плейсхолдерами). * @return mixed при sql запросе - ресурс выполненного запроса * при использовании memcache - двумерный массив с результатом запроса * при отложенном запросе - TRUE * при запросе текста запроса - строка с запросом * при ошибке - FALSE */ public function &squery($sql = '', $orig_sql = NULL) { $this->error = ''; $this->res = NULL; $this->oRes = NULL; $sto = ''; if (isset($this->_stby_log_row)) { unset($this->_stby_log_row); } if ($sql === '') { $this->sql = $this->sqls; $this->sqls = ''; } else { $this->sql = $sql; } $this->origSql = $orig_sql ? $orig_sql : $this->sql; if (self::$timeout >= 0) { $sto = 'SET statement_timeout = ' . self::$timeout . ';'; if (self::$timeout == self::DEFAULT_TIMEOUT) { $this->setTimeout(-1); // т.к. сбросили в умолчание, в след. раз не нужно устанавливать. } } if ($this->mode >= 0) { $exec = TRUE; $this->time = microtime(TRUE); if ($this->mode == 1) { $md5 = md5($this->sql); $this->res = $this->mem->get($md5); if (!empty($this->res)) { $exec = FALSE; } } if ($this->mode == 2) { // stats temp $trace = debug_backtrace(); $line = $trace[$this->traceLevel - 1]['line']; $stats = $this->memcached->get(self::MPREFIX . 'S'); if (empty($stats)) { $stats = array(); } // stats temp $hash = self::MPREFIX . 'D_' . md5($this->sql); $keys = array(); $exec = TRUE; $version = (int) ($this->time * 100); if ($this->keys) { $this->res = $this->memcached->getMulti(array_merge($this->keys, array($hash))); $exec = !(bool) $this->res[$hash]; foreach ($this->keys as $v) { if (empty($this->res[$v])) { $keys[$v] = $version; $exec = TRUE; } else { if (!$rebuild && $this->res[$v] > $this->res[$hash]['ver']) { $exec = TRUE; } } } } if (!$exec) { $this->res =& $this->res[$hash]['data']; // stats temp $stats[$line]['mem'] = (int) $stats[$line]['mem'] + 1; $this->memcached->set(self::MPREFIX . 'S', $stats); // stats temp } } if ($exec) { for ($i = 0, $only_master = false; $i < 2; $i++) { $ts = microtime(true); $cn = $this->connect(false, $only_master); pg_set_client_encoding($cn, 'WIN1251'); $this->res = @pg_query($cn, $sto . $this->sql); $tt = microtime(true) - $ts; if (!$this->res) { $tt = 0; $this->err(pg_last_error($cn), $this->sql, $this->traceLevel, $pgcode); if (!$i && ($pgcode == DB::PG_ERR_READ_ONLY || $pgcode == DB::PG_ERR_RECOVERY_CONFLICT)) { $only_master = true; continue; } } if (isset($this->_stby_log_row)) { $pfx = strpos($this->realAlias, DB::STBY_SUFFIX) ? 'standby_' : 'master_'; $this->_stby_log_row[$pfx . 'time'] += $tt; $this->_stby_log_row[$pfx . 'cnt']++; $this->_stby_log_row['ro_errors_cnt'] += (int) $only_master; } break; } if ($this->mode == 1 && $this->res !== FALSE) { $this->oRes = $this->res; $this->res = pg_fetch_all($this->res); $this->mem->set($md5, $this->res, $this->ttl, $this->mgkey); } if ($this->mode == 2 && $this->res !== FALSE) { $this->oRes = $this->res; $this->res = pg_fetch_all($this->res); if ($keys) { $this->memcached->setMulti($keys); } $this->memcached->set($hash, array('ver' => $version, 'data' => $this->res), $this->ttl); // stats temp $stats[$line]['db'] = (int) $stats[$line]['db'] + 1; $this->memcached->set(self::MPREFIX . 'S', $stats); // stats temp } } $this->time = microtime(TRUE) - $this->time; if ($this->debug) { $c = count($this->debugLog); $trace = debug_backtrace(); $this->debugLog[$c]['file'] = $this->debug; $this->debugLog[$c]['text'] .= "\n-- [" . date("Y-m-d H:i:s") . "] "; $this->debugLog[$c]['text'] .= "------------------------------------------------------------------\n"; $this->debugLog[$c]['text'] .= "FILE: {$trace[$this->traceLevel - 1]['file']}\n"; $this->debugLog[$c]['text'] .= "LINE: {$trace[$this->traceLevel - 1]['line']}\n"; $this->debugLog[$c]['text'] .= "TIME: {$this->time} sec\n"; $this->debugLog[$c]['text'] .= "MODE: {$this->mode}\n"; $this->debugLog[$c]['text'] .= "SOURCE: " . ($exec ? "DB" : "CACHE") . "\n"; if ($this->mode == 2) { $this->debugLog[$c]['text'] .= "KEYS: " . var_export($this->keys, TRUE) . "\n"; } $this->debugLog[$c]['text'] .= "RESULT: " . ($this->res !== FALSE ? "OK" : "ERROR") . "\n"; $this->debugLog[$c]['text'] .= "{$this->sql}\n"; } $this->keys = array(); $this->traceLevel = 1; $this->mode = 0; } else { if ($this->mode == -1) { $this->sqls .= preg_replace("/;\\s*\$/", "", $this->sql) . "; "; $this->mode = 0; $this->res = TRUE; } else { if ($this->mode == -2) { $this->mode = 0; $this->res = $this->sql; } } } $this->_sqlType = 0; return $this->res; }
/** * @param $key * * @return mixed */ function &get($key) { $result = $this->_cache->get($this->_prefix . $key); return $result; }
/** * Get cached data from memcache by id and group * * @access public * @param string $id The cache data id * @param string $group The cache data group * @param boolean $checkTime True to verify cache time expiration threshold * @return mixed Boolean false on failure or a cached data string * @since 1.5 */ function get($id, $group, $checkTime) { $cache_id = $this->_getCacheId($id, $group); return $this->_db->get($cache_id); }
/** * @param $key * * @return mixed */ public function get($key) { $result = $this->_cache->get($this->_prefix . $key); return unserialize($result); }
/** * Fetches the data associated with the key passed from the Redis server. * @see cecilia\core.StorageAdapter::get() */ public function get($key) { $data = $this->_conn->get($this->prefix . $key); return $data ? $data : false; }
/** * 读取缓存,失败或缓存失效时返回 false * * @param string $id * * @return mixed */ function get($id) { return $this->_conn->get($id); }