コード例 #1
0
ファイル: Registry.php プロジェクト: brucewu16899/routeros
 /**
  * Creates a registry.
  * 
  * @param string $uri An URI to bind the registry to.
  */
 public function __construct($uri)
 {
     $this->shm = SHM::factory(__CLASS__ . ' ' . $uri);
     if (-1 === self::$requestId) {
         self::$requestId = $this->shm->add('requestId', 0) ? 0 : $this->shm->inc('requestId');
     }
     $this->instanceId = ++self::$instanceIdSeed;
     $this->shm->add('responseBuffer_' . $this->getOwnershipTag(), array());
 }
コード例 #2
0
ファイル: SHM.php プロジェクト: pear2/cache_shm
    /**
     * Clears the persistent storage.
     *
     * Clears the persistent storage, i.e. removes all keys. Locks are left
     * intact.
     *
     * @return void
     */
    public abstract function clear();
    /**
     * Retrieve an external iterator
     *
     * Returns an external iterator.
     *
     * @param string|null $filter   A PCRE regular expression.
     *     Only matching keys will be iterated over.
     *     Setting this to NULL matches all keys of this instance.
     * @param bool        $keysOnly Whether to return only the keys,
     *     or return both the keys and values.
     *
     * @return \Traversable An array with all matching keys as array keys,
     *     and values as array values. If $keysOnly is TRUE, the array keys are
     *     numeric, and the array values are key names.
     */
    public abstract function getIterator($filter = null, $keysOnly = false);
}
SHM::registerAdapter('\\' . __NAMESPACE__ . '\\SHM\\Adapter\\Placebo');
SHM::registerAdapter('\\' . __NAMESPACE__ . '\\SHM\\Adapter\\Wincache');
SHM::registerAdapter('\\' . __NAMESPACE__ . '\\SHM\\Adapter\\APCu');
SHM::registerAdapter('\\' . __NAMESPACE__ . '\\SHM\\Adapter\\APC');
コード例 #3
0
ファイル: TcpClient.php プロジェクト: slrondon/MikrotikCenter
 /**
  * Creates a new connection with the specified options.
  * 
  * @param string   $host    Hostname (IP or domain) of the server.
  * @param int      $port    The port on the server.
  * @param bool     $persist Whether or not the connection should be a
  *     persistent one.
  * @param float    $timeout The timeout for the connection.
  * @param string   $key     A string that uniquely identifies the
  *     connection.
  * @param string   $crypto  Encryption setting. Must be one of the
  *     NetworkStream::CRYPTO_* constants. By default, encryption is
  *     disabled. If the setting has an associated scheme for it, it will be
  *     used, and if not, the setting will be adjusted right after the
  *     connection is estabilished.
  * @param resource $context A context for the socket.
  */
 public function __construct($host, $port, $persist = false, $timeout = null, $key = '', $crypto = parent::CRYPTO_OFF, $context = null)
 {
     $this->streamType = '_CLIENT';
     if (strpos($host, ':') !== false) {
         $host = "[{$host}]";
     }
     $flags = STREAM_CLIENT_CONNECT;
     if ($persist) {
         $flags |= STREAM_CLIENT_PERSISTENT;
     }
     $timeout = null == $timeout ? ini_get('default_socket_timeout') : $timeout;
     $key = rawurlencode($key);
     if (null === $context) {
         $context = stream_context_get_default();
     } elseif (!is_resource($context) || 'stream-context' !== get_resource_type($context)) {
         throw $this->createException('Invalid context supplied.', 6);
     }
     $hasCryptoScheme = array_key_exists($crypto, static::$cryptoScheme);
     $scheme = $hasCryptoScheme ? static::$cryptoScheme[$crypto] : 'tcp';
     $this->uri = "{$scheme}://{$host}:{$port}/{$key}";
     set_error_handler(array($this, 'handleError'));
     try {
         parent::__construct(stream_socket_client($this->uri, $this->errorNo, $this->errorStr, $timeout, $flags, $context));
         restore_error_handler();
     } catch (E $e) {
         restore_error_handler();
         if (0 === $this->errorNo) {
             throw $this->createException('Failed to initialize socket.', 7, $e);
         }
         throw $this->createException('Failed to connect with socket.', 8, $e);
     }
     if ($hasCryptoScheme) {
         $this->crypto = $crypto;
     } elseif (parent::CRYPTO_OFF !== $crypto) {
         $this->setCrypto($crypto);
     }
     $this->setIsBlocking(parent::CRYPTO_OFF === $crypto);
     if ($persist) {
         $this->shmHandler = SHM::factory(__CLASS__ . ' ' . $this->uri . ' ');
         self::$lockState[$this->uri] = self::DIRECTION_NONE;
     }
 }