Skip to content

Latest commit

 

History

History
152 lines (125 loc) · 3.96 KB

arangodb-client.md

File metadata and controls

152 lines (125 loc) · 3.96 KB

ArangoDB PHP Client

$arangoClient = new ArangoClient($config);

Configuration

Upon creation, you can alter the default configuration of the client. The following options are available:

  • endpoint = 'http://localhost:8529'
  • connection = 'Keep-Alive'
  • version = 1.1
  • host = null
  • port = null
  • username = null
  • password = null
  • database = '_system'
  • jsonStreamDecoderThreshold = 1 * 1024 * 1024
$config = [
    'endpoint' => 'http://localhost:8529',
    'username' => 'your-database-username',
    'password' => 'your-database-password',
    'database'=> 'your-database'
];

$arangoClient = new ArangoClient($config);

Speed vs response size

JSON response decoding is normally done by the default json_decode method. This method is optimized for speed and can take a large amount of memory; up to ~ 20x of the JSON size.

Therefor we use halaxa/json-machine to stream decode for responses larger than 1MB. You can alter this cutoff by setting the jsonStreamDecoderThreshold to a different size in Bytes.

This removed any memory issues at the cost of speed.

Support Guzzle configuration

In addition to the above mentioned options you can use the following Guzzle 7 specific options:

Endpoint vs host/port

Some common packages and frameworks work with a host/port combination by default. When no endpoint is provided it is constructed from these two options.

$config = [
    'host' => 'http://localhost',
    'port' => '8529',
    'username' => 'your-database-username',
    'password' => 'your-database-password',
    'database'=> 'your-database'
];

$arangoClient = new ArangoClient($config);

Functions

request(string $method, string $uri, array $options = [], ?string $database = null): stdClass

Send a request to ArangoDB's HTTP REST API. This is mostly for internal use but allows you to use unsupported endpoints.

$arangoClient->request(
    'get',
     '/_api/version', 
     [
        'query' => [
            'details' => $details
        ]
    ]
]);

rawRequest(string $method, string $uri, array|HttpRequestOptions $options = []): ResponseInterface|null

Returns the raw response of the request. Note that the request itself is made against the configured endpoint but the databasename is not automatically prepended to the uri as opposed to a regular request.

$arangoClient->rawRequest(
    'get',
     '/_api/version', 
     [
        'query' => [
            'details' => $details
        ]
    ]
]);

getConfig(): array

Get the current configuration.

$arangoClient->getConfig()

getUser(): string

Return the username;

$arangoClient->getUser();

setDatabase(string $name): void

Set the database to be used for the upcoming requests

$arangoClient->setDatabase('ArangoClientDB');

getDatabase(): string

Return the database name;

$database = $arangoClient->getDatabase();

schema(): SchemaManager

Pass chained method to the schema manager.

$arangoClient->schema()->createCollection('users');

admin(): AdminManager

Pass chained method to the admin manager.

$arangoClient->admin()->getVersion();

connect(array $config = [], ?GuzzleClient $httpClient = null): void

You can update the config by calling the connect method. This replaces the underlying connection and prepares the connection for any requests that follow.

$config = [
    'host' => 'http://localhost',
    'port' => '8529',
    'username' => 'your-other-database-username',
    'password' => 'your-other-database-password',
    'database'=> 'your-other-database'
];

$arangoClient->connect($config): void

disconnect(): bool

Disconnect from the current keep-alive connection, if any.

$arangoClient->disconnect();