本文整理汇总了PHP中memcache_pconnect函数的典型用法代码示例。如果您正苦于以下问题:PHP memcache_pconnect函数的具体用法?PHP memcache_pconnect怎么用?PHP memcache_pconnect使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了memcache_pconnect函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: pdb_get_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);
}
示例2: _cache_init
function _cache_init()
{
global $config;
global $_mch;
if (!is_null($_mch)) {
return;
}
$_mch = memcache_pconnect($config['memcache']['host']);
}
示例3: __construct
/**
* Accepts the 2-d array with details of memcached servers
*
* @param array $servers
*/
protected function __construct(array $servers)
{
if (!$servers) {
trigger_error('No memcache servers to connect', E_USER_WARNING);
}
for ($i = 0, $n = count($servers); $i < $n; ++$i) {
($con = memcache_pconnect(key($servers[$i]), current($servers[$i]))) && ($this->mc_servers[] = $con);
}
$this->mc_servers_count = count($this->mc_servers);
if (!$this->mc_servers_count) {
$this->mc_servers[0] = null;
}
}
示例4: mcached_conn
function mcached_conn()
{
global $config, $mem_flag, $mem_conn;
if ($mem_flag != 1) {
if ($config['mcache']['version'] == 0) {
$mem_conn = memcache_pconnect($config['mcache']['host'], 11211);
} else {
$mem_conn = new Memcached();
$mem_conn->addServer($config['mcache']['host'], 11211);
}
$mem_flag = 1;
}
return $mem_conn;
}
示例5: delete_search_keys
function delete_search_keys()
{
$dbh = new PDO('mysql:dbname=' . AppConfig::gacv("AC_db") . ';host=' . AppConfig::gacv("AC_server"), AppConfig::gacv("AC_user"), AppConfig::gacv("AC_pass"));
$memcache_obj = memcache_pconnect('localhost', 11211);
$sql = sprintf("select search_key from %s ", "memcache_search_keys");
$sth = $dbh->prepare($sql, array(PDO::ATTR_CURSOR, PDO::CURSOR_FWDONLY));
//
$sth->execute();
$res = $sth->fetchAll(PDO::FETCH_BOTH);
//echo $sql.$this->lookup_tbl_id_col;//
foreach ($res as $ar) {
memcache_delete($memcache_obj, $ar["search_key"], 0);
}
/* Delete all rows from the FRUIT table */
$count = $dbh->exec("DELETE FROM memcache_search_keys");
}
示例6: MCache_connect
function MCache_connect($name)
{
// use link for adding connection into global $Config
$settings =& loadConfig('memcache')['memcache'][$name];
// get connect if it already exists
if (!is_null($settings['connect'])) {
return $settings['connect'];
}
$mcConnect = memcache_pconnect($settings['hostname'], $settings['port']);
if (!$mcConnect) {
exit("Memcache connect error.");
}
// remember connection
$settings['connect'] = $mcConnect;
return $mcConnect;
}
示例7: __construct
public function __construct($queueName = '', $maxqueue = 1, $canRewrite = false, $expire = 0, $config = '')
{
if (empty($config)) {
self::$client = memcache_pconnect('127.0.0.1', 11211);
} elseif (is_array($config)) {
//array('host'=>'127.0.0.1','port'=>'11211')
self::$client = memcache_pconnect($config['host'], $config['port']);
} elseif (is_string($config)) {
//"127.0.0.1:11211"
$tmp = explode(':', $config);
$conf['host'] = isset($tmp[0]) ? $tmp[0] : '127.0.0.1';
$conf['port'] = isset($tmp[1]) ? $tmp[1] : '11211';
self::$client = memcache_pconnect($conf['host'], $conf['port']);
}
if (!self::$client) {
return false;
}
ignore_user_abort(true);
//当客户断开连接,允许继续执行
set_time_limit(0);
//取消脚本执行延时上限
$this->access = false;
$this->sleepTime = 1000;
$expire = empty($expire) ? 0 : (int) $expire + 1;
$this->expire = $expire;
$this->queueName = $queueName;
$this->retryNum = 20000;
$this->MAXNUM = $maxqueue != null ? $maxqueue : 1;
$this->canRewrite = $canRewrite;
$this->getHeadAndTail();
if (!isset($this->HEAD) || empty($this->HEAD)) {
$this->HEAD = 0;
}
if (!isset($this->TAIL) || empty($this->TAIL)) {
$this->TAIL = 0;
}
if (!isset($this->LEN) || empty($this->LEN)) {
$this->LEN = 0;
}
}
示例8: cache_connect
function cache_connect()
{
if (!cfg('memcache/enabled')) {
return false;
}
if (isset($GLOBALS['obj']) && $GLOBALS['obj']['memcache']) {
return true;
}
$mcUrl = explode(':', cfg('memcache/server'));
$mc = null;
$GLOBALS['errorhandler_ignore'] = true;
$mc = @memcache_pconnect($mcUrl[0], $mcUrl[1] + 0);
$GLOBALS['errorhandler_ignore'] = false;
if ($mc === false) {
$GLOBALS['config']['memcache']['enabled'] = false;
$GLOBALS['errors']['memcache'] = 'Could not connect to memcache server ' . cfg('memcache/server');
logError('', 'memcache: could not connect to server ' . cfg('memcache/server'));
return false;
}
$GLOBALS['obj']['memcache'] = $mc;
return true;
}
示例9: prep
/**
Initialize cache backend
@return bool
@public
**/
static function prep()
{
if (!self::$vars['CACHE']) {
return TRUE;
}
if (is_bool(self::$vars['CACHE'])) {
// Auto-detect backend
self::detect();
}
if (preg_match('/^(apc)|(memcache)=(.+)|(xcache)|(folder)=(.+\\/)/i', self::$vars['CACHE'], $match)) {
if (isset($match[5]) && $match[5]) {
if (!is_dir($match[6])) {
self::mkdir($match[6]);
}
// File system
self::$backend = array('type' => 'folder', 'id' => $match[6]);
} else {
$ext = strtolower($match[1] ?: ($match[2] ?: $match[4]));
if (!extension_loaded($ext)) {
trigger_error(sprintf(self::TEXT_PHPExt, $ext));
return FALSE;
}
if (isset($match[2]) && $match[2]) {
// Open persistent MemCache connection(s)
$mcache = NULL;
foreach (self::split($match[3]) as $server) {
// Hostname:port
list($host, $port) = explode(':', $server);
if (is_null($port)) {
// Use default port
$port = 11211;
}
// Connect to each server
if (is_null($mcache)) {
$mcache = memcache_pconnect($host, $port);
} else {
memcache_add_server($mcache, $host, $port);
}
}
// MemCache
self::$backend = array('type' => $ext, 'id' => $mcache);
} else {
// APC and XCache
self::$backend = array('type' => $ext);
}
}
self::$buffer = NULL;
return TRUE;
}
// Unknown back-end
trigger_error(self::TEXT_Backend);
return FALSE;
}
示例10: var2
if ($a = $allan2->get('test2')) {
print "Got value : " . $a . "<br>";
var2($flags);
}
$flags = false;
if ($a = $allan3->get('test3')) {
print "Got value : " . $a . "<br>";
var2($flags);
}
$flags = false;
if ($a = $allan4->get('test4')) {
print "Got value : " . $a . "<br>";
var2($flags);
}
print "..<br>";
$memcache_obj = memcache_pconnect('127.0.0.1', 11211);
memcache_set($memcache_obj, 'test5', 'sdf2', false, 10);
memcache_set($memcache_obj, 'test6', true, false, 10);
memcache_set($memcache_obj, 'test7', false, false, 10);
$temp2 = array();
$temp = array($temp2);
memcache_set($memcache_obj, 'test8', $temp, false, 10);
#memcache_set($memcache_obj, 'test8', NULL, false, 10);
$flags = false;
if ($a = memcache_get($memcache_obj, 'test5', $flags)) {
print "5:Got value : " . $a . "<br>";
if ($flags) {
print "Got flags";
} else {
print "No flags";
}
示例11: connect
/**
* Lazy initialiser for memcache connection. Uses pconnect for to take
* advantage of the persistence pool where possible.
*/
private function connect()
{
if ($this->connection) {
return;
}
if (class_exists("Memcached")) {
$this->mc = new \Memcached();
$this->mc->addServer($this->host, $this->port);
$this->connection = true;
} else {
$this->connection = memcache_pconnect($this->host, $this->port);
}
if (!$this->connection) {
$error = "Couldn't connect to memcache server";
$this->log('error', $error);
throw new CacheException($error);
}
}
示例12: prep
/**
Initialize framework level-2 cache
@return boolean
@private
**/
private static function prep()
{
if (!isset(F3::$global['CACHE'])) {
// Extensions usable as cache back-ends
$_exts = array_intersect(explode('|', 'apc|xcache'), get_loaded_extensions());
foreach (array_keys($_exts, '') as $_null) {
unset($_exts[$_null]);
}
$_exts = array_merge($_exts, array());
F3::$global['CACHE'] = $_exts[0] ?: 'folder=' . F3::$global['BASE'] . 'cache/';
}
if (preg_match('/^(?:(folder)\\=(.+\\/)|(apc)|(memcache)=(.+))|(xcache)/i', F3::$global['CACHE'], $_match)) {
if ($_match[1]) {
if (!file_exists($_match[2])) {
if (!is_writable(dirname($_match[2])) && function_exists('posix_getpwuid')) {
$_uid = posix_getpwuid(posix_geteuid());
F3::$global['CONTEXT'] = array($_uid['name'], realpath(dirname($_match[2])));
trigger_error(F3::TEXT_Write);
return;
}
// Create the framework's cache folder
mkdir($_match[2], 0755);
}
// File system
self::$l1cache = array('type' => 'folder', 'id' => $_match[2]);
} else {
$_ext = strtolower($_match[3] ?: ($_match[4] ?: $_match[6]));
if (!extension_loaded($_ext)) {
F3::$global['CONTEXT'] = $_ext;
trigger_error(F3::TEXT_PHPExt);
return;
}
if ($_match[4]) {
// Open persistent MemCache connection(s)
// Multiple servers separated by semi-colon
$_pool = explode(';', $_match[5]);
$_mcache = NULL;
foreach ($_pool as $_server) {
// Hostname:port
list($_host, $_port) = explode(':', $_server);
if (is_null($_port)) {
// Use default port
$_port = 11211;
}
// Connect to each server
if (is_null($_mcache)) {
$_mcache = memcache_pconnect($_host, $_port);
} else {
memcache_add_server($_mcache, $_host, $_port);
}
}
// MemCache
self::$l1cache = array('type' => $_ext, 'id' => $_mcache);
} else {
// APC and XCache
self::$l1cache = array('type' => $_ext);
}
}
self::$l1cache['current'] = FALSE;
return TRUE;
}
// Unknown back-end
trigger_error(self::TEXT_Backend);
return FALSE;
}
示例13: connect
/**
* Lazy initialiser for memcache connection. Uses pconnect for to take
* advantage of the persistence pool where possible.
*/
private function connect()
{
if ($this->connection) {
return;
}
if (class_exists("Memcached")) {
$this->mc = new Memcached();
$this->mc->addServer($this->host, $this->port);
$this->connection = true;
} else {
$this->connection = memcache_pconnect($this->host, $this->port);
}
if (!$this->connection) {
$error = "Couldn't connect to memcache server";
$this->client->getLogger()->error($error);
throw new Postman_Google_Cache_Exception($error);
}
}
示例14: connect
private function connect()
{
if (!($this->connection = @memcache_pconnect($this->host, $this->port))) {
throw new Google_CacheException("Couldn't connect to memcache server");
}
}
示例15: error_reporting
<?php
error_reporting(E_ALL);
# Limit script runtime to 5 minutes
set_time_limit(300);
require_once "./config.default.php";
# If there are any overrides include them now
if (!is_readable('./config.php')) {
echo "<H2>WARNING: Configuration file config.php does not exist. Please\n notify your system administrator.</H2>";
} else {
include_once './config.php';
}
######################################################
# Connect to memcache
######################################################
$memcache = memcache_pconnect($memcache_server, $memcache_port);
if ($memcache) {
if (!isset($_GET['datetime'])) {
$datetime = date('YmdH');
$unixtime = time() - 7200;
} else {
$datetime = $_GET['datetime'];
$unixtime = strtotime($datetime . "00");
}
$formatted_date = date('m/d/Y H', $unixtime);
$time_prev = $unixtime - 3600;
$prev_timeperiod = date('YmdH', $time_prev);
$time_after = $unixtime + 3600;
$next_timeperiod = date('YmdH', $time_after);
?>
Shows only GET requests with more than <?php