本文整理汇总了PHP中Memcached::getVersion方法的典型用法代码示例。如果您正苦于以下问题:PHP Memcached::getVersion方法的具体用法?PHP Memcached::getVersion怎么用?PHP Memcached::getVersion使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Memcached
的用法示例。
在下文中一共展示了Memcached::getVersion方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
/**
* Constructor
*
* Instantiate the memcached cache object
*
* @param int $lifetime
* @param string $host
* @param int $port
* @param int $weight
* @throws Exception
* @return Memcached
*/
public function __construct($lifetime = 0, $host = 'localhost', $port = 11211, $weight = 1)
{
parent::__construct($lifetime);
if (!class_exists('Memcached', false)) {
throw new Exception('Error: Memcached is not available.');
}
$this->memcached = new \Memcached();
$this->addServer($host, $port, $weight);
$version = $this->memcached->getVersion();
if (isset($version[$host . ':' . $port])) {
$this->version = $version[$host . ':' . $port];
}
}
示例2: factory
public static function factory(Configuration $conf)
{
switch (strtolower($conf['session-server']['type'])) {
case 'memcache':
$memcache = new \Memcache();
if (!@$memcache->connect($conf['session-server']['host'], $conf['session-server']['port'])) {
throw new RuntimeException(sprintf('Unable to connect to memcache server at %s:%s', $conf['session-server']['host'], $conf['session-server']['port']));
}
return new MemcacheSessionHandler($memcache);
break;
case 'memcached':
$memcached = new \Memcached();
if (!@$memcached->addServer($conf['session-server']['host'], $conf['session-server']['port'])) {
throw new RuntimeException(sprintf('Unable to connect to memcached server at %s:%s', $conf['session-server']['host'], $conf['session-server']['port']));
}
$memcached->getVersion();
if (\Memcached::RES_SUCCESS !== $memcached->getResultCode()) {
throw new RuntimeException(sprintf('Unable to connect to memcached server at %s:%s', $conf['session-server']['host'], $conf['session-server']['port']));
}
return new MemcachedSessionHandler($memcached);
break;
case 'mongo':
case 'pdo':
throw new RuntimeException(sprintf('Session handler %s is not yet supported', $conf['session-server']['type']));
break;
default:
throw new RuntimeException(sprintf('Session handler %s is not a valid type', $conf['session-server']['type']));
break;
}
}
示例3: ping
/**
* Check if we are still connected to the cache server, reconnect if not.
*
* @return bool
*/
private function ping()
{
if (!$this->connected) {
return false;
}
switch (NN_CACHE_TYPE) {
case self::TYPE_REDIS:
try {
return (bool) $this->server->ping();
} catch (\RedisException $error) {
// nothing to see here, move along
}
break;
case self::TYPE_MEMCACHED:
$versions = $this->server->getVersion();
if ($versions) {
foreach ($versions as $version) {
if ($version != "255.255.255") {
return true;
}
}
}
break;
case self::TYPE_APC:
return true;
default:
return false;
}
$this->connect();
return $this->connected;
}
示例4: connect
/**
* Connect to memcached server
*/
public function connect()
{
if (class_exists('Memcached') && extension_loaded('memcached')) {
$this->memcached = new Memcached();
} else {
return;
}
$servers = self::getMemcachedServers();
if (!$servers) {
return;
}
foreach ($servers as $server) {
$this->memcached->addServer($server['ip'], $server['port'], (int) $server['weight']);
}
$this->is_connected = in_array('255.255.255', $this->memcached->getVersion(), TRUE) === FALSE;
}
示例5: validateConnection
/**
* Validate the given Memcached connection.
*
* @param \Memcached $memcached
* @return \Memcached
*/
protected function validateConnection($memcached)
{
$status = $memcached->getVersion();
if (!is_array($status)) {
throw new RuntimeException('No Memcached servers added.');
}
if (in_array('255.255.255', $status) && count(array_unique($status)) === 1) {
throw new RuntimeException('Could not establish Memcached connection.');
}
return $memcached;
}
示例6: connect
protected static function connect($servers)
{
$memcache = new \Memcached();
foreach ($servers as $server) {
$memcache->addServer($server['host'], $server['port'], $server['weight']);
}
if ($memcache->getVersion() === false) {
throw new \Exception('Could not establish memcached connection.');
}
return $memcache;
}
示例7: skip
/**
* Skip the test if Memcached extension is unavailable.
*
* @return void
*/
public function skip()
{
$extensionExists = extension_loaded('memcached');
$message = 'The libmemcached extension is not installed.';
$this->skipIf(!$extensionExists, $message);
$M = new \Memcached();
$M->addServer('127.0.0.1', 11211);
$message = 'The memcached daemon does not appear to be running on 127.0.0.1:11211';
$result = $M->getVersion();
$this->skipIf(empty($result), $message);
unset($M);
}
示例8: connect
/**
* Create a new Memcached connection instance.
*
* @param array $servers
* @param null $memcache
*
* @return \Memcached|null
* @throws \RuntimeException
*/
protected static function connect(array $servers, $memcache = null)
{
if (!$memcache) {
$memcache = new \Memcached();
}
foreach ($servers as $server) {
$memcache->addServer($server['host'], $server['port'], $server['weight']);
}
if ($memcache->getVersion() === false) {
throw new \RuntimeException('could not establish memcached connection!');
}
return $memcache;
}
示例9: connect
/**
* @throws \MemcachedException
*
* @return void
*/
public function connect()
{
if (!$this->resource) {
$resource = new PhpMemcached();
$resource->addServer(isset($this->config['host']) ? $this->config['host'] : '', isset($this->config['port']) ? $this->config['port'] : null);
//ensure that values from multi calls are returned in the same order as requested
//@see http://www.php.net/manual/de/memcached.constants.php
$resource->setOption(PhpMemcached::GET_PRESERVE_ORDER, true);
$resource->getVersion();
if ($resource->getResultCode() !== 0) {
throw new MemcachedException('Could not connect to any memcached server');
}
$this->resource = $resource;
}
}
示例10: setResource
/**
* @param array|\ArrayAccess|MemcachedSource $resource
* @throws \Cache\Exception\InvalidArgumentException
* @return Memcached
*/
public function setResource($resource)
{
if ($resource instanceof MemcachedSource) {
if (!$resource->getVersion()) {
throw new Exception\InvalidArgumentException('Invalid memcached resource');
}
$this->resource = $resource;
return $this;
}
if (is_string($resource)) {
$resource = array($resource);
}
if (!is_array($resource) && !$resource instanceof \ArrayAccess) {
throw new Exception\InvalidArgumentException(sprintf('%s: expects an string, array, or Traversable argument; received "%s"', __METHOD__, is_object($resource) ? get_class($resource) : gettype($resource)));
}
$host = $port = $weight = $persistent_id = null;
// array(<host>[, <port>[, <weight> [,<persistent_id>]]])
if (isset($resource[0])) {
$host = (string) $resource[0];
if (isset($resource[1])) {
$port = (int) $resource[1];
}
if (isset($resource[2])) {
$weight = (string) $resource[2];
}
if (isset($resource[3])) {
$persistent_id = (string) $resource[3];
}
} elseif (isset($resource['host'])) {
$host = (string) $resource['host'];
if (isset($resource['port'])) {
$port = (int) $resource['port'];
}
if (isset($resource['weight'])) {
$weight = (int) $resource['weight'];
}
if (isset($resource['persistent_id'])) {
$persistent_id = (string) $resource['persistent_id'];
}
}
if (!$host) {
throw new Exception\InvalidArgumentException('Invalid memcached resource, option "host" must be given');
}
$this->resource = array('host' => $host, 'port' => $port, 'weight' => $weight, 'persistent_id' => $persistent_id);
}
示例11: Memcached
<?php
header("Content-Type:text/html;charset=utf-8");
if (!class_exists('Memcached')) {
echo 'PHP Memcached extension was not installed';
exit;
}
echo "Use PHP Memcached extension.<br />";
//连接
$mem = new Memcached();
$mem->addServer("127.0.0.1", 11211) or die("Could not connect");
//显示版本
$version = current($mem->getVersion());
echo "Memcached Server version: " . $version . "<br />";
//保存数据
$mem->set('key1', 'This is first value', 60);
$val = $mem->get('key1');
echo "Get key1 value: " . $val . "<br />";
//替换数据
$mem->replace('key1', 'This is replace value', 60);
$val = $mem->get('key1');
echo "Get key1 value: " . $val . "<br />";
//保存数组
$arr = array('aaa', 'bbb', 'ccc', 'ddd');
$mem->set('key2', $arr, 60);
$val2 = $mem->get('key2');
echo "Get key2 value: ";
print_r($val2);
echo "<br />";
//删除数据
$mem->delete('key1');
示例12: displayAjaxTestServer
public function displayAjaxTestServer()
{
/* PrestaShop demo mode */
if (_PS_MODE_DEMO_) {
die(Tools::displayError('This functionality has been disabled.'));
}
/* PrestaShop demo mode*/
if (Tools::isSubmit('action') && Tools::getValue('action') == 'test_server') {
$host = pSQL(Tools::getValue('sHost', ''));
$port = (int) Tools::getValue('sPort', 0);
$type = Tools::getValue('type', '');
if ($host != '' && $port != 0) {
$res = 0;
if ($type == 'memcached') {
if (extension_loaded('memcached') && @fsockopen($host, $port)) {
$memcache = new Memcached();
$memcache->addServer($host, $port);
$res = in_array('255.255.255', $memcache->getVersion(), true) === false;
}
} else {
if (function_exists('memcache_get_server_status') && function_exists('memcache_connect') && @fsockopen($host, $port)) {
$memcache = @memcache_connect($host, $port);
$res = @memcache_get_server_status($memcache, $host, $port);
}
}
die(Tools::jsonEncode(array($res)));
}
}
die;
}
示例13: Memcache
}
echo '</strong><br>';
echo __('Memcache', 'bulletproof-security') . ': <strong>';
if (extension_loaded('memcache')) {
$memcache = new Memcache();
@$memcache->connect('localhost', 11211);
echo __('Memcache Extension is Loaded - ', 'bulletproof-security') . __('Version: ', 'bulletproof-security') . @$memcache->getVersion();
} else {
_e('Memcache Extension is Not Loaded', 'bulletproof-security');
}
echo '</strong><br>';
echo __('Memcached', 'bulletproof-security') . ': <strong>';
if (extension_loaded('memcached')) {
$memcached = new Memcached();
@$memcached->addServer('localhost', 11211);
echo __('Memcached Extension is Loaded - ', 'bulletproof-security') . __('Version: ', 'bulletproof-security') . @$memcached->getVersion();
} else {
_e('Memcached Extension is Not Loaded', 'bulletproof-security');
}
echo '</strong><br>';
echo '</span>';
?>
</td>
<td> </td>
<td rowspan="2" class="bps-table_cell">
<?php
if (is_multisite() && $blog_id != 1) {
echo '<font color="blue"><strong>' . __('MySQL DB Info is not displayed on Network/Multisite subsites', 'bulletproof-security') . '</strong></font><br><br>';
} else {
示例14: getVersion
/**
* Get server pool memcached version information.
*
* @link http://www.php.net/manual/en/memcached.getversion.php
*
* @return array Array of server versions, one entry per server.
*/
public function getVersion()
{
return $this->m->getVersion();
}
示例15: Memcached
<?php
$memc = new Memcached();
$servers = [['host' => 'localhost', 'port' => 11211, 'weight' => 50], ['localhost', 22222, 50]];
$memc->addServers($servers);
var_dump($memc->getVersion());