Exemple #1
0
 /**
  * Gets the OrientSocket, and establishes the connection if required.
  *
  * @return \PhpOrient\Protocols\Binary\OrientSocket
  *
  * @throws SocketException
  * @throws PhpOrientWrongProtocolVersionException
  */
 public function connect()
 {
     if (!$this->connected) {
         if (empty($this->hostname) && empty($this->port)) {
             throw new SocketException('Can not initialize a connection ' . 'without connection parameters');
         }
         if (!extension_loaded("sockets")) {
             throw new SocketException('Can not initialize a connection ' . 'without socket extension enabled. Please check you php.ini');
         }
         $this->_socket = @socket_create(AF_INET, SOCK_STREAM, getprotobyname('tcp'));
         socket_set_block($this->_socket);
         socket_set_option($this->_socket, SOL_SOCKET, SO_RCVTIMEO, array('sec' => self::READ_TIMEOUT, 'usec' => 0));
         socket_set_option($this->_socket, SOL_SOCKET, SO_SNDTIMEO, array('sec' => self::WRITE_TIMEOUT, 'usec' => 0));
         $x = @socket_connect($this->_socket, $this->hostname, $this->port);
         if (!is_resource($this->_socket) || $x === false) {
             throw new SocketException($this->getErr() . PHP_EOL);
         }
         $protocol = Reader::unpackShort($this->read(2));
         if ($protocol > $this->protocolVersion) {
             throw new PhpOrientWrongProtocolVersionException('Protocol version ' . $protocol . ' is not supported.');
         }
         //protocol handshake
         $this->protocolVersion = $protocol;
         $this->connected = true;
     }
     return $this;
 }
Exemple #2
0
 /**
  * Read a long from the socket.
  *
  * @return int the integer read
  */
 protected function _readLong()
 {
     $this->_input_buffer .= $_read = $this->_socket->read(8);
     return Reader::unpackLong($_read);
 }
Exemple #3
0
 /**
  * (PHP 5 &gt;= 5.0.0)<br/>
  * Offset to retrieve
  * @link http://php.net/manual/en/arrayaccess.offsetget.php
  *
  * @param mixed $offset <p>
  *                      The offset to retrieve.
  *                      </p>
  *
  * @todo add support for Tree Based RidBags
  * @return ID The RecordID instance at the given offset.
  */
 public function offsetGet($offset)
 {
     if (isset($this->items[$offset])) {
         return $this->items[$offset];
     }
     if ($this->type === self::EMBEDDED) {
         $start = $this->baseOffset + $offset * 10;
         $chunk = substr($this->binaryContent, $start, 2);
         if ($chunk === false) {
             $this->items[$offset] = false;
             return $this->items[$offset];
         }
         $cluster = Reader::unpackShort(substr($this->binaryContent, $start, 2));
         $position = Reader::unpackLong(substr($this->binaryContent, $start + 2, 8));
         $this->items[$offset] = new ID($cluster, $position);
     } else {
         $this->items[$offset] = false;
     }
     return $this->items[$offset];
 }