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 __destruct() { // if we were connected, close the connection again if (is_resource($this->connection)) { memcache_close($this->connection); } }
static function disconnect() { if (CGlobal::$memcache_connect_id) { memcache_close(CGlobal::$memcache_connect_id); } return TRUE; }
function cache_delete($key, $timeout = 0) { $connection = cache_connect(); $res = memcache_delete($connection, (string) $key, (int) $timeout); memcache_close($connection); return $res; }
public function tearDown() { if ($this->mmcError) { return; } memcache_close($this->mmc); $this->mmc = null; }
public function setUp() { if ($this->mmcError) { return; } if (isset($this->conf['servers'])) { list($this->mmhost, $this->mmport) = explode(":", $this->conf['servers']); } $mmc = memcache_connect($this->mmhost, (int) $this->mmport); memcache_flush($mmc); memcache_close($mmc); }
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 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 } } } }
function test() { global $memcache_test_servers; if (!extension_loaded('memcache') || !class_exists('Memcache')) { return FALSE; } if (empty($memcache_test_servers)) { return TRUE; } // Note: will return true if at least one connection succeeds foreach ($memcache_test_servers as $memcache_server_info) { if ($memcache_obj = memcache_connect($memcache_server_info['host'], $memcache_server_info['port'])) { memcache_close($memcache_obj); return TRUE; } } return FALSE; }
function db_mysqli_query_fetch_store($mysqli, $query, $MYSQLI_TYPE) { $config = getConfig(); $params = $config['memcache']; $memcache = memcache_connect($params['host'], $params['port']); $memcacheQueryKey = 'QUERY' . md5($query); $data = memcache_get($memcache, $memcacheQueryKey); if (!empty($data)) { } else { $result = mysqli_query($mysqli, $query); $data = []; while ($row = mysqli_fetch_array($result, $MYSQLI_TYPE)) { $data[] = $row; } memcache_set($memcache, $memcacheQueryKey, $data, 0, 60 * 10); } memcache_close($memcache); return $data; }
function __destruct() { memcache_close($this->connection); }
function push($device_token,$message){ $memcache_obj = memcache_connect('192.168.133.71',21211); while(list($key,$deviceToken) = each($device_token)){ if($data['payload']=$message){ $data['deviceToken']=$deviceToken; $output = json_encode($data); memcache_set($memcache_obj,'pushqueue',$output,0,0); } } memcache_close($memcache_obj); }
public function mkdir($path, $mode, $options) { $path = trim(substr($path, 8)); //echo "回调mkdir\n"; $path = rtrim($path, '/'); $this->stat = $this->get_file_info($path); $this->stat['ctime'] = $this->stat[10] = time(); $this->stat['mode'] = $this->stat[2] = $this->dir_mode; //echo "生成新的stat数据" . print_r( $this->stat , 1 ); memcache_set($this->mc(), $path . '.meta', serialize($this->stat)); //echo "写入MC. key= " . $path.'.meta ' . memcache_get( $this->mc , $path.'.meta' ); memcache_close($this->mc); return true; }
/** * Disconnect from remote cache store * * @access public * @return boolean Disconnect successful */ public function disconnect() { if ($this->link) { return memcache_close($this->link); } return false; }
<?php $memcache = memcache_connect('10.10.20.93', 11211); //$memcache = @memcache_connect('localhost', 11211); try { if ($memcache) { echo '{"error_code":"0","error_string":"SUCCESS"}'; memcache_close($memcache); } else { echo '{"error_code":"1","error_string":"Connection to memcached failed"}'; } } catch (Exception $ex) { echo '{"error_code":"1","error_string":"' . $ex->getMessage() . '"}'; }
/** * Display some warning messages if this installation is obviously insecure!! * These warnings are only displayed to admin users * * @return void */ public static function displayWarningMessages() { if ($GLOBALS['BE_USER']->isAdmin()) { // Array containing warnings that must be displayed $warnings = array(); // If this file exists and it isn't older than one hour, the Install Tool is enabled $enableInstallToolFile = PATH_site . 'typo3conf/ENABLE_INSTALL_TOOL'; // Cleanup command, if set $cmd = \TYPO3\CMS\Core\Utility\GeneralUtility::_GET('adminWarning_cmd'); switch ($cmd) { case 'remove_ENABLE_INSTALL_TOOL': if (unlink($enableInstallToolFile)) { unset($enableInstallToolFile); } break; } // Check if the Install Tool Password is still default: joh316 if ($GLOBALS['TYPO3_CONF_VARS']['BE']['installToolPassword'] == md5('joh316')) { $url = 'install/index.php?redirect_url=index.php' . urlencode('?TYPO3_INSTALL[type]=about'); $warnings['install_password'] = sprintf($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:warning.install_password'), '<a href="' . $url . '">', '</a>'); } // Check if there is still a default user 'admin' with password 'password' (MD5sum = 5f4dcc3b5aa765d61d8327deb882cf99) $where_clause = 'username='******'TYPO3_DB']->fullQuoteStr('admin', 'be_users') . ' AND password='******'TYPO3_DB']->fullQuoteStr('5f4dcc3b5aa765d61d8327deb882cf99', 'be_users') . self::deleteClause('be_users'); $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('uid, username, password', 'be_users', $where_clause); if ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) { $url = 'alt_doc.php?returnUrl=alt_intro.php&edit[be_users][' . $row['uid'] . ']=edit'; $warnings['backend_admin'] = sprintf($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:warning.backend_admin'), '<a href="' . htmlspecialchars($url) . '">', '</a>'); } $GLOBALS['TYPO3_DB']->sql_free_result($res); // Check whether the file ENABLE_INSTALL_TOOL contains the string "KEEP_FILE" which permanently unlocks the install tool if (is_file($enableInstallToolFile) && trim(file_get_contents($enableInstallToolFile)) === 'KEEP_FILE') { $url = \TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('TYPO3_REQUEST_SCRIPT') . '?adminWarning_cmd=remove_ENABLE_INSTALL_TOOL'; $warnings['install_enabled'] = sprintf($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:warning.install_enabled'), '<span style="white-space:nowrap;">' . $enableInstallToolFile . '</span>'); $warnings['install_enabled'] .= ' <a href="' . $url . '">' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:warning.install_enabled_cmd') . '</a>'; } // Check if the encryption key is empty if ($GLOBALS['TYPO3_CONF_VARS']['SYS']['encryptionKey'] == '') { $url = 'install/index.php?redirect_url=index.php' . urlencode('?TYPO3_INSTALL[type]=config#set_encryptionKey'); $warnings['install_encryption'] = sprintf($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:warning.install_encryption'), '<a href="' . $url . '">', '</a>'); } // Check if parts of fileDenyPattern were removed which is dangerous on Apache $defaultParts = \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode('|', FILE_DENY_PATTERN_DEFAULT, TRUE); $givenParts = \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode('|', $GLOBALS['TYPO3_CONF_VARS']['BE']['fileDenyPattern'], TRUE); $result = array_intersect($defaultParts, $givenParts); if ($defaultParts !== $result) { $warnings['file_deny_pattern'] = sprintf($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:warning.file_deny_pattern_partsNotPresent'), '<br /><pre>' . htmlspecialchars(FILE_DENY_PATTERN_DEFAULT) . '</pre><br />'); } // Check if fileDenyPattern allows to upload .htaccess files which is dangerous on Apache if ($GLOBALS['TYPO3_CONF_VARS']['BE']['fileDenyPattern'] != FILE_DENY_PATTERN_DEFAULT && \TYPO3\CMS\Core\Utility\GeneralUtility::verifyFilenameAgainstDenyPattern('.htaccess')) { $warnings['file_deny_htaccess'] = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:warning.file_deny_htaccess'); } // Check if there are still updates to perform if (!\TYPO3\CMS\Core\Utility\GeneralUtility::compat_version(TYPO3_branch)) { $url = 'install/index.php?redirect_url=index.php' . urlencode('?TYPO3_INSTALL[type]=update'); $warnings['install_update'] = sprintf($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:warning.install_update'), '<a href="' . $url . '">', '</a>'); } // Check if sys_refindex is empty $count = $GLOBALS['TYPO3_DB']->exec_SELECTcountRows('*', 'sys_refindex'); $registry = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Registry'); $lastRefIndexUpdate = $registry->get('core', 'sys_refindex_lastUpdate'); if (!$count && $lastRefIndexUpdate) { $url = 'sysext/lowlevel/dbint/index.php?&id=0&SET[function]=refindex'; $warnings['backend_reference'] = sprintf($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:warning.backend_reference_index'), '<a href="' . $url . '">', '</a>', self::dateTime($lastRefIndexUpdate)); } // Check for memcached if configured $memCacheUse = FALSE; if (is_array($GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations'])) { foreach ($GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations'] as $table => $conf) { if (is_array($conf)) { foreach ($conf as $key => $value) { if (!is_array($value) && $value === 'TYPO3\\CMS\\Core\\Cache\\Backend\\MemcachedBackend') { $servers = $GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations'][$table]['options']['servers']; $memCacheUse = TRUE; break; } } } } if ($memCacheUse) { $failed = array(); $defaultPort = ini_get('memcache.default_port'); if (function_exists('memcache_connect')) { if (is_array($servers)) { foreach ($servers as $testServer) { $configuredServer = $testServer; if (substr($testServer, 0, 7) == 'unix://') { $host = $testServer; $port = 0; } else { if (substr($testServer, 0, 6) === 'tcp://') { $testServer = substr($testServer, 6); } if (strstr($testServer, ':') !== FALSE) { list($host, $port) = explode(':', $testServer, 2); } else { $host = $testServer; $port = $defaultPort; } } $memcache_obj = @memcache_connect($host, $port); if ($memcache_obj != NULL) { memcache_close($memcache_obj); } else { $failed[] = $configuredServer; } } } } if (count($failed) > 0) { $warnings['memcached'] = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:warning.memcache_not_usable') . '<br/>' . implode(', ', $failed); } } } // Hook for additional warnings if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_befunc.php']['displayWarningMessages'])) { foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_befunc.php']['displayWarningMessages'] as $classRef) { $hookObj = \TYPO3\CMS\Core\Utility\GeneralUtility::getUserObj($classRef); if (method_exists($hookObj, 'displayWarningMessages_postProcess')) { $hookObj->displayWarningMessages_postProcess($warnings); } } } if (count($warnings)) { if (count($warnings) > 1) { $securityWarnings = '<ul><li>' . implode('</li><li>', $warnings) . '</li></ul>'; } else { $securityWarnings = '<p>' . implode('', $warnings) . '</p>'; } $securityMessage = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Messaging\\FlashMessage', $securityWarnings, $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:warning.header'), \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR); $content = '<div style="margin: 20px 0px;">' . $securityMessage->render() . '</div>'; unset($warnings); return $content; } } return '<p> </p>'; }
public function __destruct() { if (is_resource($this->memcache)) { memcache_close($this->memcache); } }
/** * 关闭内存连接 * */ public function close() { memcache_close($this->memcache); }
static function close(&$conn) { if (!is_array($conn)) { return false; } if ($conn[1] == 'mongo') { try { return $conn[0]->close(); } catch (Exception $e) { $conn[4] = array($e->getCode(), $e->getMessage()); return false; } } else { if ($conn[1] == 'memcache') { return @memcache_close($conn[0]); } else { if (stripos($conn[1], "pdo_") === 0) { return is_object($conn[0]) && @$conn[0]->close(); } else { return @mysqli_close($conn[0]); } } } }
/** * 输出运算 * Filename 连载编译输出文件名 */ function output($Filename = '') { switch ($this->RunType) { //Mem编译模式 case 'MemCache': if ($Filename == 'include_page') { //直接输出文件 return $this->reader($this->FileDir[$this->ThisFile] . $this->ThisFile); } else { $FileNames = $Filename ? $Filename : $this->ThisFile; $CacheFile = $this->FileName($FileNames, $this->TplID); //检测记录时间 $updateT = memcache_get($this->Emc, $CacheFile . '_date'); $update = $this->FileUpdate($CacheFile, $updateT); $CacheData = memcache_get($this->Emc, $CacheFile); if (trim($CacheData) && $update) { //获得列表文件 unset($ks, $vs); preg_match_all('/<\\!-- ET\\_inc\\_cache\\[(.+?)\\] -->/', $CacheData, $IncFile); if (is_array($IncFile[1])) { foreach ($IncFile[1] as $ks => $vs) { $this->IncList[] = $vs; $listDate = memcache_get($this->Emc, $vs . '_date'); echo @filemtime($this->TemplateDir . $vs) . ' - ' . $listDate . '<br>'; //更新inc缓存 if (@filemtime($this->TemplateDir . $vs) > $listDate) { $update = 1; $this->inc($vs); } } //更新数据 if ($update == 1) { $CacheData = $this->ParseCode($this->FileList, $Filename); //cache date @memcache_set($this->Emc, $CacheFile . '_date', time()) or die("Failed to save data at the server."); @memcache_set($this->Emc, $CacheFile, $CacheData) or die("Failed to save data at the server."); } } //Close memcache_close($this->Emc); return $CacheData; } else { if ($Filename) { $CacheData = $this->ParseCode($this->FileList, $Filename); //cache date @memcache_set($this->Emc, $CacheFile . '_date', time()) or die("Failed to save data at the server."); @memcache_set($this->Emc, $CacheFile, $CacheData) or die("Failed to save data at the server."); //Close memcache_close($this->Emc); return $CacheData; } else { $CacheData = $this->ParseCode(); //cache date @memcache_set($this->Emc, $CacheFile . '_date', time()) or die("Failed to save data at the server."); @memcache_set($this->Emc, $CacheFile, $CacheData) or die("Failed to save data at the server2"); //Close memcache_close($this->Emc); return $CacheData; } } } break; //编译模式 //编译模式 case 'Cache': if ($Filename == 'include_page') { //直接输出文件 return $this->reader($this->FileDir[$this->ThisFile] . $this->ThisFile); } else { $FileNames = $Filename ? $Filename : $this->ThisFile; $CacheFile = $this->FileName($FileNames, $this->TplID); $CacheFile = $this->FileUpdate($CacheFile); if (@is_file($CacheFile)) { @extract($this->Value()); ob_start(); ob_implicit_flush(0); include $CacheFile; //获得列表文件 if ($EaseTemplate3_Cache != '') { unset($ks, $vs); preg_match_all('/<\\!-- ET\\_inc\\_cache\\[(.+?)\\] -->/', $EaseTemplate3_Cache, $IncFile); if (is_array($IncFile[1])) { foreach ($IncFile[1] as $ks => $vs) { $this->IncList[] = $vs; //更新inc缓存 if (@filemtime($this->TemplateDir . $vs) > @filemtime($this->CacheDir . $this->TplID . $vs . '.' . $this->Language . '.php')) { $this->inc($vs); } } } @eval('echo "' . $EaseTemplate3_Cache . '";'); $contents = ob_get_contents(); ob_end_clean(); return $contents; } } else { if ($Filename) { return $this->ParseCode($this->FileList, $Filename); } else { return $this->ParseCode(); } } } break; //替换引擎 //替换引擎 default: if ($Filename) { if ($Filename == 'include_page') { //直接输出文件 return $this->reader($this->FileDir[$this->ThisFile] . $this->ThisFile); } else { return $this->ParseCode($this->FileList); } } else { return $this->ParseCode(); } } }
/** * Disconnect from the cache */ function disconnect() { @memcache_close($this->memcache); }
/** * Checks whether TYPO3 can connect to the configured memcached servers. * * @return \TYPO3\CMS\Reports\Status An object representing whether TYPO3 can connect to the configured memcached servers */ protected function getMemcachedConnectionStatus() { $value = $GLOBALS['LANG']->getLL('status_ok'); $message = ''; $severity = \TYPO3\CMS\Reports\Status::OK; $failedConnections = array(); $defaultMemcachedPort = ini_get('memcache.default_port'); $memcachedServers = $this->getConfiguredMemcachedServers(); if (function_exists('memcache_connect') && is_array($memcachedServers)) { foreach ($memcachedServers as $testServer) { $configuredServer = $testServer; if (substr($testServer, 0, 7) == 'unix://') { $host = $testServer; $port = 0; } else { if (substr($testServer, 0, 6) === 'tcp://') { $testServer = substr($testServer, 6); } if (strstr($testServer, ':') !== FALSE) { list($host, $port) = explode(':', $testServer, 2); } else { $host = $testServer; $port = $defaultMemcachedPort; } } $memcachedConnection = @memcache_connect($host, $port); if ($memcachedConnection != NULL) { memcache_close($memcachedConnection); } else { $failedConnections[] = $configuredServer; } } } if (!empty($failedConnections)) { $value = $GLOBALS['LANG']->getLL('status_connectionFailed'); $severity = \TYPO3\CMS\Reports\Status::WARNING; $message = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:warning.memcache_not_usable') . '<br /><br />' . '<ul><li>' . implode('</li><li>', $failedConnections) . '</li></ul>'; } return GeneralUtility::makeInstance(\TYPO3\CMS\Reports\Status::class, $GLOBALS['LANG']->getLL('status_memcachedConfiguration'), $value, $message, $severity); }
public function __destruct() { memcache_close($this->memcache); }