/** * Constructor * * @param null|array|Traversable|MemcachedOptions $options * @throws Exception\ExceptionInterface */ public function __construct($options = null) { if (static::$extMemcachedMajorVersion === null) { $v = (string) phpversion('memcached'); static::$extMemcachedMajorVersion = $v !== '' ? (int) $v[0] : 0; } if (static::$extMemcachedMajorVersion < 1) { throw new Exception\ExtensionNotLoadedException('Need ext/memcached version >= 1.0.0'); } parent::__construct($options); }
/** * Constructor * * @param null|array|Traversable|MemcachedOptions $options * @throws Exception\ExceptionInterface * @return void */ public function __construct($options = null) { if (static::$extMemcachedMajorVersion === null) { $v = (string) phpversion('memcached'); static::$extMemcachedMajorVersion = ($v !== '') ? (int)$v[0] : 0; } if (static::$extMemcachedMajorVersion < 1) { throw new Exception\ExtensionNotLoadedException('Need ext/memcached version >= 1.0.0'); } parent::__construct($options); // It's ok to init the memcached instance as soon as possible because // ext/memcached auto-connects to the server on first use $this->memcached = new MemcachedResource(); $options = $this->getOptions(); // set lib options if (static::$extMemcachedMajorVersion > 1) { $this->memcached->setOptions($options->getLibOptions()); } else { foreach ($options->getLibOptions() as $k => $v) { $this->memcached->setOption($k, $v); } } $servers = $options->getServers(); if (!$servers) { $options->addServer('127.0.0.1', 11211); $servers = $options->getServers(); } $this->memcached->addServers($servers); // get notified on change options $memc = $this->memcached; $memcMV = static::$extMemcachedMajorVersion; $this->events()->attach('option', function ($event) use ($memc, $memcMV) { $params = $event->getParams(); if (isset($params['lib_options'])) { if ($memcMV > 1) { $memc->setOptions($params['lib_options']); } else { foreach ($params['lib_options'] as $k => $v) { $memc->setOption($k, $v); } } } // TODO: update on change/add server(s) }); }
/** * Constructor * * @param null|array|Traversable|MemcachedOptions $options * @throws Exception\ExceptionInterface */ public function __construct($options = null) { if (static::$extMemcachedMajorVersion === null) { $v = (string) phpversion('memcached'); static::$extMemcachedMajorVersion = $v !== '' ? (int) $v[0] : 0; } if (static::$extMemcachedMajorVersion < 1) { throw new Exception\ExtensionNotLoadedException('Need ext/memcached version >= 1.0.0'); } parent::__construct($options); // reset initialized flag on update option(s) $initialized =& $this->initialized; $this->getEventManager()->attach('option', function ($event) use(&$initialized) { $initialized = false; }); }
/** * Constructor * * @param null|array|Traversable|MemcachedOptions $options * @throws Exception * @return void */ public function __construct($options = null) { if (static::$extMemcachedMajorVersion === null) { $v = (string) phpversion('memcached'); static::$extMemcachedMajorVersion = $v !== '' ? (int) $v[0] : 0; } if (static::$extMemcachedMajorVersion < 1) { throw new Exception\ExtensionNotLoadedException('Need ext/memcached version >= 1.0.0'); } $this->memcached = new MemcachedResource(); parent::__construct($options); // It's ok to add server as soon as possible because // ext/memcached auto-connects to the server on first use // TODO: Handle multiple servers $options = $this->getOptions(); $this->memcached->addServer($options->getServer(), $options->getPort()); }