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; }
/** * 声明模板用法 */ function ETCoreStart($set = array('ID' => '1', 'TplType' => 'htm', 'CacheDir' => 'cache', 'TemplateDir' => 'template', 'AutoImage' => 'on', 'LangDir' => 'language', 'Language' => 'default', 'Copyright' => 'off', 'MemCache' => '')) { $this->TplID = (defined('TemplateID') ? TemplateID : ((int) @$set['ID'] <= 1 ? 1 : (int) $set['ID'])) . '_'; $this->CacheDir = (defined('NewCache') ? NewCache : (trim($set['CacheDir']) != '' ? $set['CacheDir'] : 'cache')) . '/'; $this->TemplateDir = (defined('NewTemplate') ? NewTemplate : (trim($set['TemplateDir']) != '' ? $set['TemplateDir'] : 'template')) . '/'; $this->Ext = @$set['TplType'] != '' ? $set['TplType'] : 'htm'; $this->AutoImage = @$set['AutoImage'] == 'off' ? 0 : 1; $this->Copyright = @$set['Copyright'] == 'off' ? 0 : 1; $this->Server = is_array($GLOBALS['_SERVER']) ? $GLOBALS['_SERVER'] : $_SERVER; $this->version = trim($_GET['EaseTemplateVer']) ? die('Ease Templae E3!') : ''; //载入语言文件 $this->LangDir = (defined('LangDir') ? LangDir : (@$set['LangDir'] != 'language' && @$set['LangDir'] ? $set['LangDir'] : 'language')) . '/'; if (is_dir($this->LangDir)) { $this->Language = defined('Language') ? Language : ($set['Language'] != 'default' && $set['Language'] ? $set['Language'] : 'default'); if (@is_file($this->LangDir . $this->Language . '.php')) { $lang = array(); @(include_once $this->LangDir . $this->Language . '.php'); $this->LangData = $lang; } } else { $this->Language = 'default'; } //缓存目录检测以及运行模式 if (@ereg(':', $set['MemCache'])) { $this->RunType = 'MemCache'; $memset = explode(":", $set['MemCache']); $this->Emc = memcache_connect($memset[0], $memset[1]) or die("Could not connect!"); } else { $this->RunType = @substr(@sprintf('%o', @fileperms($this->CacheDir)), -3) == 777 && is_dir($this->CacheDir) ? 'Cache' : 'Replace'; } $CompileBasic = array('/(\\{\\s*|<!--\\s*)inc_php:([a-zA-Z0-9_\\[\\]\\.\\,\\/\\?\\=\\#\\:\\;\\-\\|\\^]{5,200})(\\s*\\}|\\s*-->)/eis', '/<!--\\s*DEL\\s*-->/is', '/<!--\\s*IF(\\[|\\()(.+?)(\\]|\\))\\s*-->/is', '/<!--\\s*ELSEIF(\\[|\\()(.+?)(\\]|\\))\\s*-->/is', '/<!--\\s*ELSE\\s*-->/is', '/<!--\\s*END\\s*-->/is', '/<!--\\s*([a-zA-Z0-9_\\$\\[\\]\'\\"]{2,60})\\s*(AS|as)\\s*(.+?)\\s*-->/', '/<!--\\s*while\\:\\s*(.+?)\\s*-->/is', '/(\\{\\s*|<!--\\s*)lang\\:(.+?)(\\s*\\}|\\s*-->)/eis', '/(\\{\\s*|<!--\\s*)row\\:(.+?)(\\s*\\}|\\s*-->)/eis', '/(\\{\\s*|<!--\\s*)color\\:\\s*([\\#0-9A-Za-z]+\\,[\\#0-9A-Za-z]+)(\\s*\\}|\\s*-->)/eis', '/(\\{\\s*|<!--\\s*)dir\\:([^\\{\\}]{1,100})(\\s*\\}|\\s*-->)/eis', '/(\\{\\s*|<!--\\s*)run\\:(\\}|\\s*-->)\\s*(.+?)\\s*(\\{|<!--\\s*)\\/run(\\s*\\}|\\s*-->)/is', '/(\\{\\s*|<!--\\s*)run\\:(.+?)(\\s*\\}|\\s*-->)/is', '/\\{([a-zA-Z0-9_\'\\"\\[\\]\\$]{1,100})\\}/'); $this->Compile = is_array($this->Compile) ? array_merge($this->Compile, $CompileBasic) : $CompileBasic; $AnalysisBasic = array('$this->inc_php("\\2")', '";if($ET_Del==true){echo"', '";if(\\2){echo"', '";}elseif(\\2){echo"', '";}else{echo"', '";}echo"', '";\\$_i=0;foreach((array)\\1 AS \\3){\\$_i++;echo"', '";\\$_i=0;while(\\1){\\$_i++;echo"', '$this->lang("\\2")', '$this->Row("\\2")', '$this->Color("\\2")', '$this->Dirs("\\2")', '";\\3;echo"', '";\\2;echo"', '";echo \\$\\1;echo"'); $this->Analysis = is_array($this->Analysis) ? array_merge($this->Analysis, $AnalysisBasic) : $AnalysisBasic; }
public function getUsage() { if (!function_exists('memcache_get_extended_stats')) { return false; } if ($this->usage === null) { $servers = DebugBar::getConfig('memcached'); $server = array_shift($servers); $memcache = memcache_connect($server['host'], $server['port']); if ($memcache === false) { return false; } foreach ($servers as $server) { memcache_add_server($memcache, $server['host'], $server['port']); } $stats = memcache_get_extended_stats($memcache); $memory_used = 0; $memory_total = 0; foreach ($stats as $host => $usage) { $memory_used += $usage['bytes']; $memory_total += $usage['limit_maxbytes']; $this->usage[$host] = array('Version' => $usage['version'], 'Uptime' => $this->formatSeconds($usage['uptime']), 'Total memory' => $this->formatBytes($usage['limit_maxbytes']), 'Used memory' => $this->formatBytes($usage['bytes']), 'Available memory' => $this->formatBytes($usage['limit_maxbytes'] - $usage['bytes']), 'Threads / second' => $this->formatNum($usage['total_connections'] / $usage['uptime']), 'Current threads' => $usage['curr_connections'], 'Queries / second' => $this->formatNum($usage['cmd_get'] / $usage['uptime']), 'Hits' => $usage['get_hits'] . ' (' . $this->formatNum($usage['get_hits'] * 100 / $usage['cmd_get']) . '%)', 'Misses' => $usage['get_misses'] . ' (' . $this->formatNum($usage['get_misses'] * 100 / $usage['cmd_get']) . '%)', 'Inserts' => $usage['cmd_set'], 'Deletes' => $usage['delete_hits'], 'Items' => $usage['curr_items']); } $this->percent_used = $this->formatNum($memory_used * 100 / $memory_total); } return $this->usage; }
private static function getFromMemcache() { if (!XIIS_CACHE_MEMCACHE) { return; } if (!empty(self::$_outputData)) { return; } if (self::$_xiiCacheID == '') { return; } $servers = Yii::$app->memcache->getServers(); $memcache = false; foreach ($servers as $v) { $readay = @memcache_connect($v->host, $v->port); if ($readay) { $memcache = true; break; } } XiiError::ignoreError(); if (!$memcache) { self::logRecord([XIIS_DATA_FROM_MEMCACHE => self::FAIL_TO_CONNECT_MEMCACHE]); } else { $tmp = Yii::$app->memcache->get(self::$_xiiCacheID); if ($tmp) { self::$_outputData = XiiJson::decode($tmp); self::$_dataFrom = XIIS_DATA_FROM_MEMCACHE; self::logRecord([XIIS_DATA_FROM_MEMCACHE => self::SUCCESS_GET_FROM_MEMCACHE]); } else { self::logRecord([XIIS_DATA_FROM_MEMCACHE => self::FAIL_GET_FROM_MEMCACHE]); } } }
public function __construct() { if (!function_exists("memcache_connect")) { return; } $this->memcache = memcache_connect("127.0.0.1", 11211); }
public static function checkConnect() { $test = @memcache_connect('127.0.0.1', 11211); if ($test === false) { throw new Exception('memcached is _probably_ not running'); } }
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); }
/** * Connect to memcache server * * @access private * @param array Connection information * @return boolean Initiation successful */ private function _connect($server_info = array()) { if (!count($server_info)) { $this->crashed = true; return false; } if (!isset($server_info['memcache_server_1']) or !isset($server_info['memcache_port_1'])) { $this->crashed = true; return false; } $this->link = memcache_connect($server_info['memcache_server_1'], $server_info['memcache_port_1']); if (!$this->link) { $this->crashed = true; return false; } if (isset($server_info['memcache_server_2']) and isset($server_info['memcache_port_2'])) { memcache_add_server($this->link, $server_info['memcache_server_2'], $server_info['memcache_port_2']); } if (isset($server_info['memcache_server_3']) and isset($server_info['memcache_port_3'])) { memcache_add_server($this->link, $server_info['memcache_server_3'], $server_info['memcache_port_3']); } if (function_exists('memcache_set_compress_threshold')) { memcache_set_compress_threshold($this->link, 20000, 0.2); } return true; }
private function getMem() { if ($this->_mem == null) { $this->_mem = memcache_connect(getC("MEMCACHE_SERVER"), getC("MEMCACHE_PORT")); } return $this->_mem; }
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++; } }
/** * 链接memcache,保存实例化的memcache */ private function connect() { if ($this->mem) { return $this; } else { return $this->mem = memcache_connect($this->config['memcached_host'], $this->config['memcached_port']) or Debug::add('memcached连接失败'); } }
public function __construct() { $this->memcache = memcache_connect(Pluf::f('cache_memcached_server', 'localhost'), Pluf::f('cache_memcached_port', 11211)); if (false === $this->memcache) { $this->memcache = null; } $this->keyprefix = Pluf::f('cache_memcached_keyprefix', ''); }
public function setUp() { if ($this->mmcError) { return; } $this->mmc = memcache_connect('localhost', 11211); memcache_flush($this->mmc); }
function process_request() { $item_id = isset($_POST['item_id']) ? intval($_POST['item_id']) : null; $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_id) || $item_id <= 0) { die; } if (!is_null($item_name)) { $item_name = htmlspecialchars(trim($item_name)); if ($item_name === '') { die; } } if (!is_null($item_price)) { if (!preg_match("/^\\d+([.,]\\d{1,2})?\$/", $item_price)) { die; } } if (!is_null($item_description)) { $item_description = htmlspecialchars(trim($item_description)); } $item = db_get_item($item_id); if (!$item) { die; } $values = []; if (!is_null($item_name)) { $values['name'] = $item_name; } if (!is_null($item_price)) { $item_price = str_replace(',', '.', $item_price); $values['price'] = $item_price; } if (!is_null($item_description)) { $values['description'] = $item_description; } if (!is_null($item_img)) { $values['imgurl'] = $item_img; } if (!empty($values)) { db_update_item($item_id, $values); $mc_handler = memcache_connect('localhost'); memcache_delete($mc_handler, get_page_cache_key($item_id)); $min_price = min($item_price, $item['price']); pagination_rebuild_ids($mc_handler, $item_id, 1); if ($item_price == $item['price']) { $edited_pages_amount = 1; } else { $edited_pages_amount = 0; } pagination_rebuild_prices($mc_handler, $min_price, $edited_pages_amount); pagination_rebuild_prices($mc_handler, $min_price); } header('Location: /view_item.php?id=' . $item_id); }
function __construct($config = array()) { parent::__construct($config); if (defined('IS_SAE')) { $this->_mamcache = memcache_init() or trigger_error('Memcache Init Error', E_USER_ERROR); } else { $this->_mamcache = memcache_connect($this->host, $this->port) or trigger_error('Memcache Connect Error', E_USER_ERROR); } }
public function __construct($sServer = '127.0.0.1', $nPort = 11211) { if (!function_exists('memcache_connect')) { throw new \Exception('not fount memcache functions .'); } if (!($this->hMemcacheConnection = memcache_connect($sServer, $nPort))) { throw new \Exception('can not connect memcache server: ' . $sServer . ':' . $nPort); } }
public function __construct() { if (!function_exists('memcache_connect')) { FeiError('PHP环境未安装Memcache函数库!'); } $params = spExt('FeiAccessCache'); $memcache_host = isset($params['memcache_host']) ? $params['memcache_host'] : 'localhost'; $memcache_port = isset($params['memcache_port']) ? $params['memcache_port'] : '11211'; $this->mmc = memcache_connect($memcache_host, $memcache_port); }
public function __construct($options = []) { foreach ($options as $k => $v) { if (property_exists($this, $k)) { if (gettype($v) === gettype($this->{$k})) { $this->{$k} = $v; } } } $this->connect = memcache_connect($this->host, $this->port); $this->clearExpire(); }
public static function connect() { if (self::$config_setup === FALSE) { self::$host = Kohana::config('memcached.host'); self::$port = Kohana::config('memcached.port'); self::$set_flag = Kohana::config('memcached.set_flag'); self::$set_expire = Kohana::config('memcached.set_expire'); self::$delete_timeout = Kohana::config('memcached.delete_timeout'); self::$config_setup = TRUE; } return memcache_connect(self::$host, self::$port); }
/** * MemcacheProvider constructor * @param string $host * @param number $port * @throws \RuntimeException */ public function __construct($host = 'localhost', $port = 11211) { //check if memcache is available if (!class_exists('\\Memcache')) { throw new \RuntimeException("Memcache extension was not found on this server"); } //connnect to Memcache server $this->memcache = @memcache_connect($host, $port); if ($this->memcache === false) { throw new \RuntimeException("Connection to memcache server on '" . $host . "' (" . $port . ") failed"); } }
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')); }
/** * 连接数据库 * * @param mixed $host * @param mixed $port * @param mixed $timeout */ public function connect($config = array()) { if (!function_exists(memcache_connect)) { return FALSE; } $this->_config = $config; $this->memcache = @memcache_connect($config['Memcache_host'], $config['Memcache_port'], $config['Memcache_timeout']); if (!$this->memcache) { die('memcache died'); } else { } }
/** * @return mixed соединение с пулом кешей хранения сессий пользователя */ function session_getconnection() { $connection = null; $config = session_config(); foreach ($config as $v) { if (is_null($connection)) { $connection = memcache_connect($v['host']); } else { memcache_add_server($connection, $v['host']); } } return $connection; }
/** * @param array $pool конфигурация пула * * @return &array объект мемкеша с установленными серверами */ function &construct(array $pool) { $init = reset($pool); $memcache = memcache_connect($init[MemcachedFactory\CONFIGURATION_HOST], $init[MemcachedFactory\CONFIGURATION_PORT]); if ($memcache === false) { trigger_error('Ошибка memcache_connect ' . $init[MemcachedFactory\CONFIGURATION_HOST] . ':' . $init[MemcachedFactory\CONFIGURATION_PORT], E_USER_ERROR); } foreach (array_slice($pool, 1) as $server) { memcache_add_server($memcache, $server[MemcachedFactory\CONFIGURATION_HOST], $server[MemcachedFactory\CONFIGURATION_PORT]); } $Memcached = [FIELD_POOL => $pool, FIELD_MEMCACHE_OBJECT => $memcache]; return $Memcached; }
private function connect() { $time = microtime(TRUE); if (FALSE == $this->mc) { $this->mc = memcache_connect($this->memcached_host, $this->memcached_port); } if ($this->debug_mode) { $time = microtime(TRUE) - $time; $this->debug_info->time += $time; $this->debug_info->queries[] = (object) array('action' => 'CONNECT', 'key' => $this->memcached_host . ':' . $this->memcached_port, 'result' => $this->mc ? 'TRUE' : 'FALSE', 'time' => number_format($time, 5, '.', '')); } return $this->mc; }
function changeCountItemsById($id, $val) { $config = getConfig(); $params = $config['memcache']; $table = ['name' => 'item', 'dbname' => 'db_vktest', 'as' => 'i']; $mysqli = db_mysqli_connect($table['dbname']); $queryUpdate = 'UPDATE store SET countitems = countitems + ' . intval($val) . ' WHERE idstore = ' . intval($id); $resultUpdate = mysqli_query($mysqli, $queryUpdate); db_mysqli_close($mysqli); $memcache = memcache_connect($params['host'], $params['port']); memcache_flush($memcache); memcache_close($memcache); }
function setRamCache($key, $data, $depo) { if ($depo == 'ram_eaccelerator') { return eaccelerator_put($key, $data); } if ($depo == 'ram_xcache') { return xcache_set($key, $data); } if ($depo == 'ram_memcache') { $memcache_obj = memcache_connect('127.0.0.1', '11211'); return memcache_set($memcache_obj, $key, $data, 0, 86400); } return false; }
function clear_dbs() { if (class_exists("Memcached")) { $memcached = new Memcached(); $memcached->addServer(MEMCACHE_SERVER, MEMCACHE_PORT); } else { $memcached = memcache_connect(MEMCACHE_SERVER, MEMCACHE_PORT); } $key = CRM_PREFIX . "databases"; $dbs = $memcached->get($key); if (!is_null($dbs)) { $memcached->delete($key); } }
function Init() { global $SECURITY_SESSION_MC; if (isset($SECURITY_SESSION_MC)) { return true; } if (extension_loaded('memcache') && defined("BX_SECURITY_SESSION_MEMCACHE_HOST")) { $port = defined("BX_SECURITY_SESSION_MEMCACHE_PORT") ? intval(BX_SECURITY_SESSION_MEMCACHE_PORT) : 11211; $SECURITY_SESSION_MC = memcache_connect(BX_SECURITY_SESSION_MEMCACHE_HOST, $port); if (is_object($SECURITY_SESSION_MC)) { return true; } } return false; }
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; } }