function process_request() { $item_name = isset($_POST['item_name']) ? $_POST['item_name'] : null; $item_price = isset($_POST['item_price']) ? $_POST['item_price'] : null; $item_description = isset($_POST['item_description']) ? $_POST['item_description'] : null; $item_img = isset($_POST['item_img']) ? $_POST['item_img'] : null; if (is_null($item_name)) { die; } else { $item_name = htmlspecialchars(trim($item_name)); if ($item_name === '') { die; } } if (is_null($item_price) || !preg_match("/^\\d+([.,]\\d{1,2})?\$/", $item_price)) { die; } $item_price = str_replace(',', '.', $item_price); if (is_null($item_description)) { die; } else { $item_description = htmlspecialchars(trim($item_description)); } if (is_null($item_img)) { $item_img = "Null"; } $id = db_insert_item($item_name, $item_description, $item_price, $item_img); $mc_handler = memcache_connect('localhost'); if (memcache_get($mc_handler, 'total_rows') !== false) { memcache_increment($mc_handler, 'total_rows'); pagination_rebuild_ids($mc_handler, $id); pagination_rebuild_prices($mc_handler, $item_price); } header('Location: /view_item.php?id=' . $id); }
function cache_get($key) { $connection = cache_connect(); $data = memcache_get($connection, (string) $key); memcache_close($connection); return $data; }
function pdb_get_data($key, $provider, $arguments = []) { $mc_handler = memcache_pconnect(MC_HOST); $value = memcache_get($mc_handler, $key); if ($value !== false) { return $value; } else { $locking_key = 'lock_' . $key; $locking_value = microtime(true); for ($i = 0; $i < MC_LOCK_DELAY * 1000 / MC_SLEEP_TIME + 1; $i++) { $lock = memcache_add($mc_handler, $locking_key, $locking_value, 0, MC_LOCK_DELAY); if ($lock) { $value = call_user_func_array($provider, $arguments); memcache_set($mc_handler, $key, $value); memcache_delete($mc_handler, $locking_key); return $value; } else { usleep(MC_SLEEP_TIME); $value = memcache_get($mc_handler, $key); if ($value != false) { return $value; } } } } return call_user_func_array($provider, $arguments); }
public function requeue_snapshot() { ignore_user_abort(true); header("Connection: Close"); flush(); ob_end_flush(); $m = memcache_connect('127.0.0.1', 11211); $urlkey = sha1($this->snapshot_url); if (isset($_GET['requeue']) && 'true' != $_GET['requeue']) { if (memcache_get($m, $urlkey)) { die; } } memcache_set($m, $urlkey, 1, 0, 300); $requeue_url = self::renderer . "/queue?url=" . rawurlencode($this->snapshot_url) . "&f=" . urlencode($this->snapshot_file); $retval = file_get_contents($requeue_url); $tries = 1; while (false === $retval && $tries <= 5) { sleep(1); // in the event that the failed call is due to a mShots.js service restart, // we need to be a little patient as the service comes back up $retval = file_get_contents($requeue_url); $tries++; } }
function memcache_safeadd(&$memcache_obj, $key, $value, $flag, $expire) { if (memcache_add($memcache_obj, $key, $value, $flag, $expire)) { return $value == memcache_get($memcache_obj, $key); } return FALSE; }
function cache_get($key) { if (!cache_connect()) { return false; } return memcache_get(object('memcache'), $GLOBALS['config']['service']['server'] . '/' . $key); }
public function getItem($key) { if (empty($key)) { throw new CacheException('CACHE ERROR:key is empty'); } return memcache_get($this->cache, $key, self::COMP); }
function db_mysqli_query_fetch_list($mysqli, $query, $MYSQLI_TYPE) { $config = getConfig(); $params = $config['memcache']; $memcache = memcache_connect($params['host'], $params['port']); $memcacheQueryKey = 'QUERY' . $query['slow']; $data = memcache_get($memcache, $memcacheQueryKey); if (!empty($data)) { } else { if (!empty($query['fast'])) { $result = mysqli_query($mysqli, $query['fast']); } else { $result = mysqli_query($mysqli, $query['slow']); } $data = []; while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) { $data[] = $row; } //another proc /* $pid = pcntl_fork(); if ($pid == 0) {*/ memcache_set($memcache, $memcacheQueryKey, $data, 0, 60 * 10); /* posix_kill(posix_getpid(), SIGTERM); }*/ } memcache_close($memcache); return $data; }
public function get($key) { $this->check(); if (($ret = memcache_get($this->connection, $key)) === false) { return false; } return $ret; }
function memcache_version_get($memcache_obj, $key) { global $config; if ($config['mcache']['version'] == 0) { return memcache_get($memcache_obj, $key); } else { return $memcache_obj->get($key); } }
/** * Retrieve an item from the cache. * * @param string The name of the cache * @param boolean True if we should do a hard refresh * @return mixed Cache data if successful, false if failure */ function fetch($name, $hard_refresh = false) { $data = memcache_get($this->memcache, $this->unique_id . "_" . $name); if ($data === false) { return false; } else { return $data; } }
/** * Reads data from doctrine tables and return its content * @param string $id * @throws AppKitDoctrineSessionStorageException */ public function sessionRead($id) { $session = memcache_get($this->memcache, $this->prefix . $this->getParameter('session_name') . ":" . $id); if (!$session) { memcache_add($this->memcache, $this->prefix . $this->getParameter('session_name') . ":" . $id, ""); return ''; } return $session; }
public function get($key) { $expire = memcache_get($this->mmc, $this->group . '_' . $this->ver . '_time_' . $key); if (intval($expire) > time()) { return memcache_get($this->mmc, $this->group . '_' . $this->ver . '_' . $key); } else { return false; } }
function cache_get($key, $defval = false) { global $_mch; $val = memcache_get($_mch, $key); if (!$val) { return $defval; } return unserialize($val); }
function is_memcache_ok() { $mmc = @memcache_init(); if ($mmc == FALSE) { return FALSE; } else { memcache_set($mmc, "dilicms_install_test", "dilicms"); return memcache_get($mmc, "dilicms_install_test") == 'dilicms'; } }
public static function get_by_key_name($key_name) { $link = memcache_init(); if (!$key_name) { return false; } $data = memcache_get($link, $key_name); $new_obj = new Game($key_name, $data); return $new_obj; }
public function get($name) { if (!is_resource($this->memcache)) { throw new \Exception("Memcached can't connect."); } $data = memcache_get($this->memcache, $name); if ($data) { return $data; } else { throw new \Exception("cache not exists."); } }
public function testFlush() { parent::testFlush(); $mmc = memcache_connect($this->mmhost, $this->mmport); $this->assertTrue(memcache_get($mmc, 'flush1DataKey')); $this->assertTrue(memcache_get($mmc, 'flush2DataKey')); $this->assertTrue(memcache_get($mmc, 'flush3DataKey')); $this->assertTrue(jCache::flush($this->profile)); $this->assertFalse(memcache_get($mmc, 'flush1DataKey')); $this->assertFalse(memcache_get($mmc, 'flush2DataKey')); $this->assertFalse(memcache_get($mmc, 'flush3DataKey')); }
/** * Returns data from cache or NULL if data is missing or expired. * * @param string $ns Key namespace (read from config) * @param string $key Key name * @return mixed */ public function get($ns, $key) { PROFILER_IN('Cache-get'); $this->_checkNs($ns); $key = $this->_keyNs[$ns]['value'] . ':' . $key; $res = memcache_get($this->_conn($ns), $key); if (FALSE === $res) { $res = NULL; } PROFILER_OUT('Cache-get'); return $res; }
static function register_static_get($key) { $mmc = memcache_init(); if ($mmc == false) { echo "那个坑爹的Memcache加载失败啦!笨蛋!\n"; } else { if ($out = memcache_get($mmc, 'tk_' . $key)) { return $out; } else { return false; } } }
function send_email_alert($name, $title, $message, $t = 10) { // debuglog(__FUNCTION__); $last = memcache_get(controller()->memcache->memcache, "last_email_sent_{$name}"); if ($last + $t * 60 > time()) { return; } debuglog("mail('" . YAAMP_ADMIN_EMAIL . "', {$title}, ...)"); $b = mail(YAAMP_ADMIN_EMAIL, $title, $message); if (!$b) { debuglog('error sending email'); } memcache_set(controller()->memcache->memcache, "last_email_sent_{$name}", time()); }
function getRamCache($key, $depo) { if ($depo == 'ram_eaccelerator') { $data = eaccelerator_get($key); } if ($depo == 'ram_xcache') { $data = xcache_get($key); } if ($depo == 'ram_memcache') { $memcache_obj = memcache_connect('127.0.0.1', 11211); $data = memcache_get($memcache_obj, $key); } return $data; }
public function testFlush() { $kv = jKVDb::getConnection($this->profile); $kv->set('flush1DataKey', 'some data', 0); $kv->setWithTtl('flush2DataKey', 'data to remove', strtotime("+1 day")); $kv->setWithTtl('flush3DataKey', 'other data to remove', time() + 30); $this->assertTrue(memcache_get($this->mmc, 'flush1DataKey')); $this->assertTrue(memcache_get($this->mmc, 'flush2DataKey')); $this->assertTrue(memcache_get($this->mmc, 'flush3DataKey')); $this->assertTrue($kv->flush()); $this->assertFalse(memcache_get($this->mmc, 'flush1DataKey')); $this->assertFalse(memcache_get($this->mmc, 'flush2DataKey')); $this->assertFalse(memcache_get($this->mmc, 'flush3DataKey')); }
function getLocation($openid) { $mmc = memcache_init(); if ($mmc == true) { $location = memcache_get($mmc, $openid); if (!empty($location)) { return json_decode($location, true); } else { return "请先发送位置给我!\n点击底部的'+'号,再选择'位置',等地图显示出来以后,点击'发送'"; } } else { return "未启用缓存,请先开启服务器的缓存功能。"; } }
public function add_monitoring_function($name, $d1) { return; $count = memcache_get($this->memcache, "{$name}-count"); memcache_set($this->memcache, "{$name}-count", $count + 1); $d = memcache_get($this->memcache, "{$name}-time"); memcache_set($this->memcache, "{$name}-time", $d + $d1); $a = memcache_get($this->memcache, 'url-map'); if (!$a) { $a = array(); } $a[$name] = $count + 1; memcache_set($this->memcache, 'url-map', $a); }
public function getMetaData($meta_page) { $mc = memcache_connect('185.87.49.111', 11211); $key = 'getMetaData' . $meta_page; if (memcache_get($mc, $key)) { return $result = memcache_get($mc, $key); } else { $db = Db::GetConnection(); $query = $db->prepare("SELECT meta_title, meta_keywords, meta_description FROM metadata WHERE meta_page = :meta_page;"); $query->execute(array('meta_page' => "{$meta_page}")); $result = $query->fetch(); memcache_set($mc, $key, $result, MEMCACHE_COMPRESSED, 60 * 60); return $result; } }
public function __construct() { $this->session = false; $this->mem = memcache_connect('localhost', 11211); if (isset($_COOKIE['sessid'])) { $this->session_id = $_COOKIE['sessid']; $this->session = memcache_get($this->mem, 'sess_' . $this->session_id); } if ($this->session == false) { $this->create(); } else { $this->session = unserialize($this->session); if (!is_array($this->session)) { $this->session = array(); } } }
function afterLictAction($queryAssoc, $rowStore) { $config = getConfig(); /** * Count of items page,that need be cached,because * but last-1/-2/-3/-4 use slow query */ $COUNT_BEFORE_END = 5; $length = $queryAssoc['query']['length']; $itemsLast = $rowStore['countitems'] % $length; $lastPage = $rowStore['countitems'] - $itemsLast; $start = $queryAssoc['query']['start']; /** * only for last page */ if ($start == $lastPage) { //last 5 page in cache& $queryCheckPre = array_merge($queryAssoc, []); $queryCheckPre['query']['start'] = $start - 1 * $length; $queryPre = buildListItemQuery($queryCheckPre, $rowStore['countitems']); $params = $config['memcache']; $memcache = memcache_connect($params['host'], $params['port']); $memcacheQueryKey = 'QUERY' . $queryPre['slow']; $data = memcache_get($memcache, $memcacheQueryKey); memcache_close($memcache); //another proc if (empty($data)) { $pid = pcntl_fork(); if ($pid == 0) { $mysqli = db_mysqli_connect($queryAssoc['table']['dbname']); for ($i = 1; $i < $COUNT_BEFORE_END; $i++) { $queryAssoc['query']['start'] = $start - $i * $length; $sqlQueryes = buildListItemQuery($queryAssoc, $rowStore['countitems']); $rows = db_mysqli_query_fetch_list($mysqli, $sqlQueryes, MYSQLI_ASSOC); $_SESSION['list'] = ['lastitem' => $rows[count($rows) - 1], 'firstitem' => $rows[0], 'lastpage' => $queryAssoc['query']['start'], 'slowQueryType' => $sqlQueryes['slowQueryType']]; // usleep(500); } db_mysqli_close($mysqli); exit(0); //end new proc } } } }
/** * @inheritDoc */ public function get($key, $expiration = false) { $this->connect(); $ret = false; if ($this->mc) { $ret = $this->mc->get($key); } else { $ret = memcache_get($this->connection, $key); } if ($ret === false) { return false; } if (is_numeric($expiration) && time() - $ret['time'] > $expiration) { $this->delete($key); return false; } return $ret['data']; }
public function get($key) { if (FALSE == $this->mc) { if (FALSE == $this->connect()) { return FALSE; } } $key = $this->keys_prefix . $key; if ($this->debug_mode) { $time = microtime(TRUE); $res = memcache_get($this->mc, $key); $time = microtime(TRUE) - $time; $this->debug_info->time += $time; $this->debug_info->queries[] = (object) array('action' => 'GET', 'key' => $key, 'result' => !$res ? 'FALSE' : gettype($res), 'time' => number_format($time, 5, '.', '')); return $res; } return memcache_get($this->mc, $key); }