Class Brightzone\GremlinDriver\Connection

InheritanceBrightzone\GremlinDriver\Connection

Gremlin-server PHP Driver client Connection class

Example of basic use:

$connection = new Connection(['host' => 'localhost']);
$connection->open();
$resultSet = $connection->send('g.V'); //returns array with results

Some more customising of message to send can be done with the message object

$connection = new Connection(['host' => 'localhost']);
$connection->open();
$connection->message->gremlin = 'g.V';
$connection->send();

See Message for more details

Public Properties

Hide inherited properties

PropertyTypeDescriptionDefined By
$aliases array Aliases to be used for this connection. Brightzone\GremlinDriver\Connection
$emptySet bool Whether or not the driver should return empty result sets as an empty array (the default behavior is to propagate the exception from the server - yes the server throws exceptions on empty result sets. Brightzone\GremlinDriver\Connection
$graph string The graph to use. Brightzone\GremlinDriver\Connection
$host string Contains the host information required to connect to the database. Brightzone\GremlinDriver\Connection
$message Brightzone\GremlinDriver\Message Message object Brightzone\GremlinDriver\Connection
$password string The password for establishing DB connection. Brightzone\GremlinDriver\Connection
$port string Contains port information to connect to the database Default : 8182 Brightzone\GremlinDriver\Connection
$retryAttempts \Brightzone\GremlinDriver\the Number of attempts before total failure Brightzone\GremlinDriver\Connection
$retryStrategy \Brightzone\GremlinDriver\the Strategy to use for retry Brightzone\GremlinDriver\Connection
$saslMechanism string Which sasl mechanism to use for authentication. Brightzone\GremlinDriver\Connection
$ssl bool|array Whether or not we're using ssl. Brightzone\GremlinDriver\Connection
$timeout float Timeout to use for connection to Rexster. Brightzone\GremlinDriver\Connection
$username string The username for establishing DB connection. Brightzone\GremlinDriver\Connection

Protected Properties

Hide inherited properties

PropertyTypeDescriptionDefined By
$_socket resource Rexpro socket connection Brightzone\GremlinDriver\Connection

Public Methods

Hide inherited methods

MethodDescriptionDefined By
__construct() Overloading constructor to instantiate a Message instance and provide it with a default serializer. Brightzone\GremlinDriver\Connection
__destruct() Make sure the session is closed on destruction of the object Brightzone\GremlinDriver\Connection
close() Close connection to server This closes the current session on the server then closes the socket Brightzone\GremlinDriver\Connection
closeSession() Closes an open session if it exists You can use this to close open sessions on the server end. This allows to free up threads on the server end. Brightzone\GremlinDriver\Connection
getSession() Retrieve the current session UUID Brightzone\GremlinDriver\Connection
inTransaction() Return whether or not this cnnection object is in transaction mode Brightzone\GremlinDriver\Connection
isConnected() Checks if the socket is currently open Brightzone\GremlinDriver\Connection
open() Connects to socket and starts a session with gremlin-server Brightzone\GremlinDriver\Connection
run() Constructs and sends a Message entity or gremlin script to the server without waiting for a response. Brightzone\GremlinDriver\Connection
send() Constructs and sends a Message entity or gremlin script to the server and then waits for response Brightzone\GremlinDriver\Connection
transaction() Run a callback in a transaction. Brightzone\GremlinDriver\Connection
transactionStart() Start a transaction. Brightzone\GremlinDriver\Connection
transactionStop() End a transaction Brightzone\GremlinDriver\Connection

Protected Methods

Hide inherited methods

MethodDescriptionDefined By
authenticate() Builds an authentication message when challenged by the server Brightzone\GremlinDriver\Connection
makeHandshake() Make Original handshake with the server Brightzone\GremlinDriver\Connection
socketGetUnpack() Recieves binary data over the socket and parses it Brightzone\GremlinDriver\Connection

Property Details

$_socket protected property

Rexpro socket connection

protected resource $_socket null
$aliases public property

Aliases to be used for this connection. Allows users to set up whichever character on the db end such as "g" and reference it with another alias.

public array $aliases = []
$emptySet public property

Whether or not the driver should return empty result sets as an empty array (the default behavior is to propagate the exception from the server - yes the server throws exceptions on empty result sets.)

public bool $emptySet FALSE
$graph public property

The graph to use.

public string $graph null
$host public property

Contains the host information required to connect to the database.

Default: localhost

public string $host 'localhost'
$message public property

Message object

$password public property

The password for establishing DB connection. Defaults to NULL.

public string $password null
$port public property

Contains port information to connect to the database

Default : 8182

public string $port 8182
$retryAttempts public property

Number of attempts before total failure

public \Brightzone\GremlinDriver\the $retryAttempts 1
$retryStrategy public property

Strategy to use for retry

public \Brightzone\GremlinDriver\the $retryStrategy 'linear'
$saslMechanism public property

Which sasl mechanism to use for authentication. Can be either PLAIN or GSSAPI. This is ignored by gremlin-server by default but some custom server implementations may use this

public string $saslMechanism "PLAIN"
$ssl public property

Whether or not we're using ssl. If an array is set it should correspond to a stream_context_create() array.

public bool|array $ssl FALSE
$timeout public property

Timeout to use for connection to Rexster. If not set the timeout set in php.ini will be used: ini_get("default_socket_timeout")

public float $timeout null
$username public property

The username for establishing DB connection. Defaults to NULL.

public string $username null

Method Details

__construct() public method

Overloading constructor to instantiate a Message instance and provide it with a default serializer.

public void __construct ( $options = [] )
$options
__destruct() public method

Make sure the session is closed on destruction of the object

public void __destruct ( )
authenticate() protected method

Builds an authentication message when challenged by the server

protected void authenticate ( )
close() public method

Close connection to server This closes the current session on the server then closes the socket

public bool close ( )
return bool

TRUE on success

closeSession() public method

Closes an open session if it exists You can use this to close open sessions on the server end. This allows to free up threads on the server end.

public void closeSession ( )
getSession() public method

Retrieve the current session UUID

public string getSession ( )
return string

Current UUID

inTransaction() public method

Return whether or not this cnnection object is in transaction mode

public bool inTransaction ( )
return bool

TRUE if in transaction, FALSE otherwise

isConnected() public method

Checks if the socket is currently open

public bool isConnected ( )
return bool

TRUE if it is open FALSE if not

makeHandshake() protected method

Make Original handshake with the server

protected bool makeHandshake ( $origin FALSE )
$origin bool

Whether or not to provide the origin header. currently unsupported

return bool

TRUE on succes FALSE on failure

open() public method

Connects to socket and starts a session with gremlin-server

public bool open ( )
return bool

TRUE on success FALSE on error

run() public method

Constructs and sends a Message entity or gremlin script to the server without waiting for a response.

public void run ( $msg NULL, $processor '', $op 'eval', $args = [], $expectResponse TRUE )
$msg mixed

(Message|String|NULL) the message to send, NULL means use $this->message

$processor string

OpProcessor to use.

$op string

Operation to run against opProcessor.

$args array

Arguments to overwrite.

$expectResponse bool

Arguments to overwrite.

send() public method

Constructs and sends a Message entity or gremlin script to the server and then waits for response

public array send ( $msg NULL, $processor '', $op 'eval', $args = [] )
$msg mixed

(Message|String|NULL) the message to send, NULL means use $this->message

$processor string

OpProcessor to use.

$op string

Operation to run against opProcessor.

$args array

Arguments to overwrite.

return array

Reply from server.

socketGetUnpack() protected method

Recieves binary data over the socket and parses it

protected array socketGetUnpack ( )
return array

PHP native result from server

transaction() public method

Run a callback in a transaction.

The advantage of this is that it allows for fail-retry strategies

public mixed transaction ( callable $callback, $params = [] )
$callback callable

The code to execute within the scope of this transaction

$params array

The params to pass to the callback

return mixed

The return value of the provided callable

transactionStart() public method

Start a transaction.

Transaction start only makes sens if committing is set to manual on the server. Manual is not the default setting so we will assume a session UUID must exists

public bool transactionStart ( )
return bool

TRUE on success FALSE on failure

transactionStop() public method

End a transaction

public bool transactionStop ( $success TRUE )
$success bool

Should the transaction commit or revert changes

return bool

TRUE on success FALSE on failure.