本文整理汇总了PHP中memcache_connect函数的典型用法代码示例。如果您正苦于以下问题:PHP memcache_connect函数的具体用法?PHP memcache_connect怎么用?PHP memcache_connect使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了memcache_connect函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: db_mysqli_query_fetch_list
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;
}
示例2: ETCoreStart
/**
* 声明模板用法
*/
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;
}
示例3: getUsage
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;
}
示例4: getFromMemcache
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]);
}
}
}
示例5: __construct
public function __construct()
{
if (!function_exists("memcache_connect")) {
return;
}
$this->memcache = memcache_connect("127.0.0.1", 11211);
}
示例6: checkConnect
public static function checkConnect()
{
$test = @memcache_connect('127.0.0.1', 11211);
if ($test === false) {
throw new Exception('memcached is _probably_ not running');
}
}
示例7: process_request
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);
}
示例8: _connect
/**
* 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;
}
示例9: getMem
private function getMem()
{
if ($this->_mem == null) {
$this->_mem = memcache_connect(getC("MEMCACHE_SERVER"), getC("MEMCACHE_PORT"));
}
return $this->_mem;
}
示例10: requeue_snapshot
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++;
}
}
示例11: connect
/**
* 链接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连接失败');
}
}
示例12: __construct
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', '');
}
示例13: setUp
public function setUp()
{
if ($this->mmcError) {
return;
}
$this->mmc = memcache_connect('localhost', 11211);
memcache_flush($this->mmc);
}
示例14: process_request
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);
}
示例15: __construct
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);
}
}