コード例 #1
0
 /**
  * Class constructor
  *
  * @param $memcache_host, $memcache_port
  */
 public function __construct($memcache_host = '127.0.0.1', $memcache_port = 11211)
 {
     if (is_null($this->memcache) || !is_object($this->memcache)) {
         $this->memcache = new Memcache();
         if (!$this->memcache->pconnect($memcache_host, $memcache_port)) {
             throw new Exception("Error in object initialization", 2);
         }
     }
 }
コード例 #2
0
ファイル: Memcache.php プロジェクト: rosstuck/SessionHandler
 /**
  * Open up the backend
  *
  * @param string $savePath
  * @param string $sessionName
  * @return boolean
  */
 public function open($savePath, $sessionName)
 {
     $this->_backend = new Memcache();
     // Open a persistent or regular connection
     if ($this->_config['persistent']) {
         $this->_backend->pconnect($this->_config['hostname'], $this->_config['port'], $this->_config['timeout_connect']);
     } else {
         $this->_backend->connect($this->_config['hostname'], $this->_config['port'], $this->_config['timeout_connect']);
     }
 }
コード例 #3
0
ファイル: TXMemcache.php プロジェクト: billge1205/biny
 public function __construct($config)
 {
     $this->handler = new Memcache();
     if (isset($config['keep-alive']) && $config['keep-alive']) {
         $fd = $this->handler->pconnect($config['host'], $config['port'], TXConst::minute);
     } else {
         $fd = $this->handler->connect($config['host'], $config['port']);
     }
     if (!$fd) {
         throw new TXException(4004, array($config['host'], $config['port']));
     }
 }
コード例 #4
0
ファイル: PeclMemcache.php プロジェクト: justthefish/hesper
 public function __construct($host = self::DEFAULT_HOST, $port = self::DEFAULT_PORT)
 {
     $this->instance = new \Memcache();
     try {
         try {
             $this->instance->pconnect($host, $port);
         } catch (BaseException $e) {
             $this->instance->connect($host, $port);
         }
         $this->alive = true;
     } catch (BaseException $e) {
         // bad luck.
     }
 }
コード例 #5
0
 /**
  * Конструктор
  *
  * @param array $servers
  * @param boolean $persistent
  */
 public function __construct($host, $port, $persistent = false)
 {
     if (!extension_loaded('memcache') || !class_exists('Memcache')) {
         throw new _Core_Cache_Exception('Extension "memcache" is not loaded or not up to date !');
     }
     $this->server = new Memcache();
     if ($persistent) {
         $connected = $this->server->pconnect($host, $port);
     } else {
         $connected = $this->server->connect($host, $port);
     }
     if (!$connected) {
         throw new _Core_Cache_Exception('Could not connect to memcached server on ' . $host . ':' . $port . ' !');
     }
 }
コード例 #6
0
ファイル: cache.php プロジェクト: rb2/ocstoreru
 public function __construct($exp = 3600)
 {
     $this->expire = $exp;
     if (defined('CACHE_DRIVER')) {
         $this->cachedriver = CACHE_DRIVER;
     }
     if ($this->cachedriver == 'memcached') {
         $mc = new Memcache();
         if ($mc->pconnect(MEMCACHE_HOSTNAME, MEMCACHE_PORT)) {
             $this->memcache = $mc;
             $this->ismemcache = true;
         }
     }
     if (!$this->ismemcache) {
         $files = glob(DIR_CACHE . 'cache.*');
         if ($files) {
             foreach ($files as $file) {
                 $time = substr(strrchr($file, '.'), 1);
                 if ($time < time()) {
                     if (file_exists($file)) {
                         @touch($file);
                         @unlink($file);
                     }
                 }
             }
         }
     }
 }
コード例 #7
0
ファイル: memcached.php プロジェクト: nemein/openpsa
 /**
  * This handler completes the configuration.
  */
 public function _on_initialize()
 {
     if (array_key_exists('host', $this->_config)) {
         $this->_host = $this->_config['host'];
     }
     if (array_key_exists('port', $this->_config)) {
         $this->_port = $this->_config['port'];
     }
     // memcache does serialization automatically. no need for manual serialization
     $this->_auto_serialize = false;
     // Open the persistant connection.
     if (is_null(self::$memcache)) {
         self::$memcache = new Memcache();
         try {
             self::$memcache_operational = @self::$memcache->pconnect($this->_host, $this->_port);
         } catch (Exception $e) {
             // Memcache connection failed
             if ($this->_abort_on_fail) {
                 debug_add("Failed to connect to {$this->_host}:{$this->_port}. " . $e->getMessage(), MIDCOM_LOG_ERROR);
                 // Abort the request
                 throw new midcom_error("Failed to connect to {$this->_host}:{$this->_port}.");
             }
             // Otherwise we just skip caching
             debug_add("memcache handler: Failed to connect to {$this->_host}:{$this->_port}. " . $e->getMessage() . ". Serving this request without cache.", MIDCOM_LOG_ERROR);
             self::$memcache_operational = false;
         }
     }
 }
コード例 #8
0
ファイル: Memcache.php プロジェクト: radicaldesigns/amp
 function _init_connection()
 {
     if (!class_exists('Memcache')) {
         return false;
     }
     $memcache_connection = new Memcache();
     $server_list = explode(',', AMP_SYSTEM_MEMCACHE_SERVER);
     $primary_server = array_shift($server_list);
     $result = $memcache_connection->pconnect($primary_server, AMP_SYSTEM_MEMCACHE_PORT);
     if (count($server_list)) {
         foreach ($server_list as $additional_server) {
             $result = $memcache_connection->addServer($additional_server, AMP_SYSTEM_MEMCACHE_PORT) || $result;
         }
     }
     if ($result) {
         $this->set_connection($memcache_connection);
     } else {
         trigger_error(sprintf(AMP_TEXT_ERROR_CACHE_REQUEST_FAILED, 'Memcache', 'connect', 'Request: ' . $_SERVER['REQUEST_URI']));
         $result = $this->_restart_memcached();
         //try again
         if ($result) {
             $this->set_connection($memcache_connection);
         }
     }
     return $result;
 }
コード例 #9
0
function elggcache_cacheinit()
{
    global $CFG, $messages;
    //memcache_debug(true);
    if (!empty($CFG->elggcache_enabled)) {
        static $memcacheconn;
        //var_dump($memcacheconn);
        if (!isset($memcacheconn)) {
            if (!empty($CFG->elggcache_debug)) {
                $messages[] = 'connecting to memcache<br />';
            }
            $memcacheconn = new Memcache();
            $memcacheconn->pconnect($CFG->elggcache_memcache_host, $CFG->elggcache_memcache_port);
        }
        //var_dump($memcacheconn);
        if (empty($memcacheconn) || !is_resource($memcacheconn->connection)) {
            $CFG->elggcache_enabled = false;
            if (!empty($CFG->elggcache_debug)) {
                $messages[] = 'failed connect to memcache<br />';
            }
        }
    } else {
        $memcacheconn = false;
    }
    //$stats = $memcacheconn->getExtendedStats();
    //var_dump($stats);
    //var_dump($memcacheconn);
    return $memcacheconn;
}
コード例 #10
0
ファイル: Memcache.php プロジェクト: aiyeyun/aiyeyun
 public function __construct()
 {
     $host = '127.0.0.1';
     $port = 11211;
     $memcache = new \Memcache();
     $memcache->pconnect($host, $port);
     $this->memcache = $memcache;
 }
 /**
  * {@inheritDoc}
  */
 public function __construct($name)
 {
     $this->prefix = $name;
     if (!self::$memcache) {
         self::$memcache = new Memcache();
         $host = Config::get('cache_host');
         $port = Config::get('cache_port');
         if (Config::get('cache_memcache_pconnect')) {
             if (!@self::$memcache->pconnect($host, $port)) {
                 throw new CacheException("Couldn't connect to memcache server");
             }
         } else {
             if (!@self::$memcache->connect($host, $port)) {
                 throw new CacheException("Couldn't connect to memcache server");
             }
         }
     }
 }
コード例 #12
0
ファイル: MemCache.php プロジェクト: difra-org/difra
 /**
  * Detect if backend is available
  * @return bool
  */
 public static function isAvailable()
 {
     if (!extension_loaded('memcache')) {
         return false;
     }
     if (self::$memcache) {
         return true;
     }
     $serverList = [['unix:///tmp/memcache', 0], ['127.0.0.1', 11211]];
     self::$memcache = new \MemCache();
     foreach ($serverList as $serv) {
         if (@self::$memcache->pconnect($serv[0], $serv[1])) {
             self::$server = $serv[0];
             self::$port = $serv[1];
             return true;
         }
     }
     return false;
 }
コード例 #13
0
 public function enableMemcache()
 {
     $this->memcacheConfig = ConfigManager::getConfig("Db", "Memcache")->AuxConfig;
     if ($this->memcacheConfig->enabled) {
         $memcache = new Memcache();
         if ($memcache->pconnect($this->memcacheConfig->host, $this->memcacheConfig->port)) {
             Minify::setCache(new Minify_Cache_Memcache($memcache));
         }
     }
 }
コード例 #14
0
 /**
  * Create the Memcache connection
  *
  * @return  void
  *
  * @since   11.1
  * @throws  RuntimeException
  */
 protected function getConnection()
 {
     if (!static::isSupported()) {
         throw new RuntimeException('Memcache Extension is not available');
     }
     $config = JFactory::getConfig();
     $host = $config->get('memcache_server_host', 'localhost');
     $port = $config->get('memcache_server_port', 11211);
     // Create the memcache connection
     static::$_db = new Memcache();
     if ($config->get('memcache_persist', true)) {
         $result = @static::$_db->pconnect($host, $port);
     } else {
         $result = @static::$_db->connect($host, $port);
     }
     if (!$result) {
         // Null out the connection to inform the constructor it will need to attempt to connect if this class is instantiated again
         static::$_db = null;
         throw new JCacheExceptionConnecting('Could not connect to memcache server');
     }
 }
コード例 #15
0
ファイル: cache.memcache.func.php プロジェクト: ChainBoy/wxfx
function cache_memcache()
{
    global $_W;
    static $memcacheobj;
    if (!extension_loaded('memcache')) {
        return error(1, 'Class Memcache is not found');
    }
    if (empty($memcacheobj)) {
        $config = $_W['config']['setting']['memcache'];
        $memcacheobj = new Memcache();
        if ($config['pconnect']) {
            $connect = $memcacheobj->pconnect($config['server'], $config['port']);
        } else {
            $connect = $memcacheobj->connect($config['server'], $config['port']);
        }
    }
    return $memcacheobj;
}
コード例 #16
0
ファイル: bootstrap.php プロジェクト: victorfcm/VuFind-Plus
function initMemcache()
{
    //Connect to memcache
    /** @var Memcache $memCache */
    global $memCache;
    global $timer;
    global $configArray;
    // Set defaults if nothing set in config file.
    $host = isset($configArray['Caching']['memcache_host']) ? $configArray['Caching']['memcache_host'] : 'localhost';
    $port = isset($configArray['Caching']['memcache_port']) ? $configArray['Caching']['memcache_port'] : 11211;
    $timeout = isset($configArray['Caching']['memcache_connection_timeout']) ? $configArray['Caching']['memcache_connection_timeout'] : 1;
    // Connect to Memcache:
    $memCache = new Memcache();
    if (!@$memCache->pconnect($host, $port, $timeout)) {
        //Try again with a non-persistent connection
        if (!$memCache->connect($host, $port, $timeout)) {
            PEAR_Singleton::raiseError(new PEAR_Error("Could not connect to Memcache (host = {$host}, port = {$port})."));
        }
    }
    $timer->logTime("Initialize Memcache");
}
コード例 #17
0
ファイル: mem.php プロジェクト: segasho/metro
 /**
  * memcahcedへの接続オープン
  * @param string $name
  * @return unknown_type
  */
 public function memOpen($name)
 {
     $this->dsn_name = $name;
     if (!isset(self::$connection[$name])) {
         $dsn = $this->dsn_name;
         $memcache = new Memcache();
         // ADD START 2010/10/04 hhasegawa
         $connectFlg = self::OFF_FLG;
         // 接続処理
         if ($memcache->pconnect($dsn)) {
             $connectFlg = self::ON_FLG;
         }
         if ($connectFlg === self::ON_FLG) {
             $this->memcache = $memcache;
             self::$connection[$name] = $memcache;
         } else {
             return false;
         }
     } else {
         $this->memcache = self::$connection[$name];
     }
 }
コード例 #18
0
function flushmemcache($key = false, $host, $port, $debug = false)
{
    if (!function_exists('memcache_pconnect')) {
        if ($debug) {
            ADOConnection::outp(" Memcache module PECL extension not found!<br>\n");
        }
        return;
    }
    $memcache = new Memcache();
    if (!@$memcache->pconnect($host, $port)) {
        if ($debug) {
            ADOConnection::outp(" Can't connect to memcache server on: {$host}:{$port}<br>\n");
        }
        return;
    }
    if ($key) {
        if (!$memcache->delete($key)) {
            if ($debug) {
                ADOConnection::outp("CacheFlush: {$key} entery doesn't exist on memcached server!<br>\n");
            }
        } else {
            if ($debug) {
                ADOConnection::outp("CacheFlush: {$key} entery flushed from memcached server!<br>\n");
            }
        }
    } else {
        if (!$memcache->flush()) {
            if ($debug) {
                ADOConnection::outp("CacheFlush: Failure flushing all enteries from memcached server!<br>\n");
            }
        } else {
            if ($debug) {
                ADOConnection::outp("CacheFlush: All enteries flushed from memcached server!<br>\n");
            }
        }
    }
    return;
}
コード例 #19
0
ファイル: twextra_model.php プロジェクト: raj4126/twextra
 function mc_pconnect()
 {
     static $memcache = null;
     if ($this->get_hostname() == 'http://twetest.com') {
         return null;
     }
     if (!$memcache) {
         $memcache = new Memcache();
         //open a persistent connection
         if (!$memcache->pconnect('localhost', 11211)) {
             $memcache = null;
             //.................................
             //send system maintenance message
             $to = '*****@*****.**';
             $subject = 'memcached not running';
             $message = 'start memcached daemon';
             $headers = 'From: contact@twextra.com' . "\r\n" . 'Reply-To: contact@twextra.com' . "\r\n" . 'X-Mailer: PHP/' . phpversion();
             //mail($to, $subject, $message, $headers);
             //....................................
         }
     }
     return $memcache;
 }
 /**
  * Constructs this backend
  *
  * @param mixed $options Configuration options - depends on the actual backend
  * @author Robert Lemke <*****@*****.**>
  */
 public function __construct($options = array())
 {
     if (!extension_loaded('memcache')) {
         throw new t3lib_cache_Exception('The PHP extension "memcached" must be installed and loaded in ' . 'order to use the Memcached backend.', 1213987706);
     }
     parent::__construct($options);
     $this->memcache = new Memcache();
     $defaultPort = ini_get('memcache.default_port');
     if (!count($this->servers)) {
         throw new t3lib_cache_Exception('No servers were given to Memcache', 1213115903);
     }
     foreach ($this->servers as $serverConfiguration) {
         if (substr($serverConfiguration, 0, 7) == 'unix://') {
             $host = $serverConfiguration;
             $port = 0;
         } else {
             if (substr($serverConfiguration, 0, 6) === 'tcp://') {
                 $serverConfiguration = substr($serverConfiguration, 6);
             }
             if (strstr($serverConfiguration, ':') !== FALSE) {
                 list($host, $port) = explode(':', $serverConfiguration, 2);
             } else {
                 $host = $serverConfiguration;
                 $port = $defaultPort;
             }
         }
         if ($this->serverConnected) {
             $this->memcache->addserver($host, $port);
         } else {
             // pconnect throws PHP warnings when it cannot connect!
             $this->serverConnected = @$this->memcache->pconnect($host, $port);
         }
     }
     if (!$this->serverConnected) {
         t3lib_div::sysLog('Unable to connect to any Memcached server', 'core', 3);
     }
 }
コード例 #21
0
 /**
  * @return bool false on error
  */
 protected function reconnect()
 {
     $this->memcache = null;
     if ($this->connectAttempts >= self::MAX_CONNECT_ATTEMPTS) {
         return false;
     }
     $connectResult = false;
     $connStart = microtime(true);
     while ($this->connectAttempts < self::MAX_CONNECT_ATTEMPTS) {
         $this->connectAttempts++;
         $memcache = new Memcache();
         //$memcache->setOption(Memcached::OPT_BINARY_PROTOCOL, true);			// TODO: enable when moving to memcached v1.3
         $curConnStart = microtime(true);
         if ($this->persistent) {
             $connectResult = @$memcache->pconnect($this->hostName, $this->port);
         } else {
             $connectResult = @$memcache->connect($this->hostName, $this->port);
         }
         if ($connectResult || microtime(true) - $curConnStart < 0.5) {
             // retry only if there's an error and it's a timeout error
             break;
         }
         self::safeLog("got timeout error while connecting to memcache...");
     }
     $connTook = microtime(true) - $connStart;
     self::safeLog("connect took - {$connTook} seconds to {$this->hostName}:{$this->port} attempts {$this->connectAttempts}");
     if (class_exists("KalturaMonitorClient")) {
         KalturaMonitorClient::monitorConnTook($this->hostName, $connTook);
     }
     if (!$connectResult) {
         self::safeLog("failed to connect to memcache");
         return false;
     }
     $this->memcache = $memcache;
     return true;
 }
コード例 #22
0
ファイル: share.php プロジェクト: oizhaolei/websysadmin
error_reporting(0);
ini_set('display_errors', '0');
session_start();
ob_start("mb_output_handler");
header("Content-Type: text/html; charset=UTF-8");
header("Cache-Control: no-cache");
header("Pragma: no-cache");
date_default_timezone_set("Asia/Tokyo");
// storage api
include_once "../config.inc";
// setting mbstring
mb_internal_encoding("UTF-8");
// browser flag
$g_isIE = strstr($_SERVER['HTTP_USER_AGENT'], "MSIE") ? true : false;
$memcached = new Memcache();
if (!$memcached->pconnect(MEMCACHED_IP, MEMCACHED_PORT)) {
    $memcached = null;
}
include_once 'log4php/Logger.php';
Logger::configure(__DIR__ . '/../log4php.properties');
//////////////////////////////////////////////////////////////////
//                      共通関数
//////////////////////////////////////////////////////////////////
// ************************ 常数の定義 ***************************
// ************************ 共通関数の定義 ***********************
//-------------------------
// 1. チE�Eタベ�Eス管琁E��連
//-------------------------
$g_transaction = false;
// チE�Eタベ�Eスに接綁E
function connectDB()
コード例 #23
0
 public static function init()
 {
     if (self::disabled() || !class_exists("Memcache")) {
         return null;
     }
     self::$memcache = new Memcache();
     $host = defined("HL_MEMCACHE_HOST") ? HL_MEMCACHE_HOST : '127.0.0.1';
     self::$memcache->pconnect($host);
 }
コード例 #24
0
 private static function getMemcache()
 {
     $memcache = new Memcache();
     $memcache->pconnect('localhost', 11211);
     return $memcache;
 }
コード例 #25
0
 protected function getMemcache()
 {
     $memcache = new Memcache();
     $memcache->pconnect('localhost', 11211);
     return $memcache;
 }
コード例 #26
0
 private function initMemcache()
 {
     global $memCache;
     // Set defaults if nothing set in config file.
     $host = isset($configArray['Caching']['memcache_host']) ? $configArray['Caching']['memcache_host'] : 'localhost';
     $port = isset($configArray['Caching']['memcache_port']) ? $configArray['Caching']['memcache_port'] : 11211;
     $timeout = isset($configArray['Caching']['memcache_connection_timeout']) ? $configArray['Caching']['memcache_connection_timeout'] : 1;
     // Connect to Memcache:
     $memCache = new Memcache();
     if (!$memCache->pconnect($host, $port, $timeout)) {
         PEAR_Singleton::raiseError(new PEAR_Error("Could not connect to Memcache (host = {$host}, port = {$port})."));
     }
     $this->logTime("Initialize Memcache");
 }
コード例 #27
0
function flushmemcache($key = false, &$host, $port, $debug = false)
{
    if (is_object($host)) {
        $memcache =& $host;
    } else {
        $memcache = new Memcache();
        if (!@$memcache->pconnect($host, $port)) {
            if ($debug) {
                ADOConnection::outp(" Can't connect to memcache server on: {$host}:{$port}<br>\n");
            }
            return;
        }
    }
    if ($key) {
        if (!$memcache->delete($key)) {
            if ($debug) {
                ADOConnection::outp("CacheFlush: {$key} entery doesn't exist on memcached server!<br>\n");
            }
        } else {
            if ($debug) {
                ADOConnection::outp("CacheFlush: {$key} entery flushed from memcached server!<br>\n");
            }
        }
    } else {
        if (!$memcache->flush()) {
            if ($debug) {
                ADOConnection::outp("CacheFlush: Failure flushing all enteries from memcached server!<br>\n");
            }
        } else {
            if ($debug) {
                ADOConnection::outp("CacheFlush: All enteries flushed from memcached server!<br>\n");
            }
        }
    }
    return;
}
コード例 #28
0
ファイル: Memcache.php プロジェクト: Nycto/Round-Eights
 /**
  * Opens the memcache connection
  *
  * @return \r8\Cache\Memcache Returns a self reference
  */
 public function connect()
 {
     // If we are already connected
     if ($this->isConnected()) {
         return $this;
     }
     $link = new \Memcache();
     // Connect with persistence, if they requested it
     if ($this->persistent) {
         $result = @$link->pconnect($this->host, $this->port, $this->timeout);
     } else {
         $result = @$link->connect($this->host, $this->port, $this->timeout);
     }
     // If an error occured while connect, translate it to an exception
     if (!$result) {
         $error = \error_get_last();
         throw new \r8\Exception\Cache\Connection($error['message'], $error['type']);
     }
     // Now that we have verified the connection, save it
     $this->link = $link;
     return $this;
 }
コード例 #29
0
ファイル: common.php プロジェクト: Tycheo/Carbon-Forum
require dirname(__FILE__) . "/includes/PDO.class.php";
$DB = new Db(DBHost, DBName, DBUser, DBPassword);
//Initialize MemCache(d) / Redis
$MCache = false;
if (EnableMemcache) {
    if (extension_loaded('memcached')) {
        //MemCached
        $MCache = new Memcached(MemCachePrefix . 'Cache');
        //Using persistent memcached connection
        if (!count($MCache->getServerList())) {
            $MCache->addServer(MemCacheHost, MemCachePort);
        }
    } elseif (extension_loaded('memcache')) {
        //MemCache
        $MCache = new Memcache();
        $MCache->pconnect(MemCacheHost, MemCachePort);
    } elseif (extension_loaded('redis')) {
        //Redis
        //https://github.com/phpredis/phpredis
        $MCache = new Redis();
        $MCache->pconnect(MemCacheHost, MemCachePort);
    }
}
//Load configuration
$Config = array();
if ($MCache) {
    $Config = $MCache->get(MemCachePrefix . 'Config');
}
if (!$Config) {
    foreach ($DB->query('SELECT ConfigName,ConfigValue FROM ' . $Prefix . 'config') as $ConfigArray) {
        $Config[$ConfigArray['ConfigName']] = $ConfigArray['ConfigValue'];
コード例 #30
0
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<head>
	<link href="style.css" rel="stylesheet">
</head>

<div class="productList">
<?php 
include 'my_memcache.php';
$link = mysql_connect('localhost', 'nfuogibo', 'T6iT0i0a1j') or die('Не удалось соединиться: ' . mysql_error());
mysql_select_db('nfuogibo_goods') or die('Не удалось выбрать базу данных nfuogibo_goods');
$memcache_host = 'localhost';
$memcache_port = 11211;
$memcache = new Memcache();
if (!$memcache->pconnect($memcache_host, $memcache_port)) {
    die("Memcached не доступен: {$memcache_host}:{$memcache_port}");
}
echo '<div class = "header">';
echo '<table class = "menu"><tr>';
echo '<td class = "menu">';
echo '<a href="index.php">Вернуться к списку товаров</a>';
echo '</td>';
echo '</tr></table>';
echo '</div>';
echo '<div class = "product">';
if (isset($_POST['delete'])) {
    $aDoor = $_POST['delete'];
    $N = count($aDoor);
    for ($i = 0; $i < $N; $i++) {
        $ath = sqlSet("DELETE FROM goods WHERE id = " . $aDoor[$i] . ";", $aDoor[$i]);
        echo 'Товар с id ' . $aDoor[$i] . ' уcпешно удален.<br>';
    }