Skip to content

Commit fcf7fd9

Browse files
committed
Merge branch 'devel' of https://github.com/arangodb/arangodb-php into 3.3
2 parents 9b0608b + 5c71768 commit fcf7fd9

14 files changed

+803
-86
lines changed

CHANGELOG.md

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,59 @@
1-
Release notes for the ArangoDB-PHP driver 3.2.0
1+
Release notes for the ArangoDB-PHP driver 3.3.x
22
===============================================
3+
4+
Starting from release 3.3.1, the PHP driver has support for automatic failover, for
5+
ArangoDB servers that are started in the active failover mode. This setup requires
6+
using ArangoDB 3.3.
7+
8+
In order to use automatic failover from the PHP driver, simply change the "endpoint"
9+
attribute of the connection options from a simple endpoint string into an array of
10+
endpoint strings:
11+
12+
$connectionOptions = [
13+
ConnectionOptions::OPTION_ENDPOINT => [ 'tcp://localhost:8531', 'tcp://localhost:8532', 'tcp://localhost:8530' ],
14+
...
15+
];
16+
$connection = new Connection($connectionOptions);
17+
18+
instead of just
19+
20+
$connectionOptions = [
21+
ConnectionOptions::OPTION_ENDPOINT => 'tcp://localhost:8530',
22+
...
23+
];
24+
$connection = new Connection($connectionOptions);
25+
26+
27+
Additionally, retrieving the endpoint value of `ConnectionOptions` will now always
28+
return an array of endpoints. For the single-server case, the returned value will be
29+
an array with the specified endpoint. When active failover is used, the result will
30+
be an array with the specified endpoints or the endpoints found (added) at runtime.
31+
For example, in
32+
33+
$options = [ ConnectionOptions::OPTION_ENDPOINT => 'tcp://127.0.0.1:8529' ];
34+
$co = new ConnectionOptions($options);
35+
print_r($co[ConnectionOptions::OPTION_ENDPOINT]);
36+
37+
This will now print an array (`[ 'tcp://127.0.0.1:8529' ]`) and not just the string
38+
(`tcp://127.0.0.1:8529'). Client applications that retrieve the endpoint value via
39+
the `ConnectionOptions` object and expect it to be a string should be adjusted to
40+
pick the first value from the now-returned result array instead.
41+
42+
Using the port option for setting up `ConnectionOptions` and reading it back is now
43+
deprecated and will not be useful when using different endpoints with different port
44+
numbers.
45+
46+
For example, reading the `port` option here will provide just one of the specified
47+
ports, so it should be avoided:
48+
49+
$options = [ ConnectionOptions::OPTION_ENDPOINT => [ 'tcp://127.0.0.1:8529', 'tcp://127.0.0.1:8530' ] ];
50+
$co = new ConnectionOptions($options);
51+
print_r($co[ConnectionOptions::OPTION_PORT]);
52+
53+
54+
Release notes for the ArangoDB-PHP driver 3.2.x
55+
===============================================
56+
357
- the default value for the authentication type of the `Connection` class is now `Basic`
458

559
- the default value for the connection type is now `Keep-Alive` and not `Close`

README.md

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
- [Cloning the git repository](#cloning_git)
2323
- [How to use the PHP client](#howto_use)
2424
- [Setting up the connection options](#setting_up_connection_options)
25+
- [Setting up failover](#setting_up_failover)
2526
- [Creating a collection](#creating_collection)
2627
- [Creating a document](#creating_document)
2728
- [Adding exception handling](#adding_exception_handling)
@@ -204,6 +205,65 @@ When updating a document that was previously/concurrently updated by another use
204205
* fail with a conflict error: if you prefer that, set OPTION_UPDATE_POLICY to conflict
205206

206207

208+
<a name="setting_up_failover"></a>
209+
## Setting up active failover
210+
211+
By default the PHP client will connect to a single endpoint only,
212+
by specifying a string value for the endpoint in the `ConnectionOptions`,
213+
e.g.
214+
215+
```php
216+
$connectionOptions = [
217+
ArangoConnectionOptions::OPTION_ENDPOINT => 'tcp://127.0.0.1:8529'
218+
];
219+
```
220+
221+
To set up multiple servers to connect to, it is also possible to specify
222+
an array of servers instead:
223+
224+
```php
225+
$connectionOptions = [
226+
ConnectionOptions::OPTION_ENDPOINT => [ 'tcp://localhost:8531', 'tcp://localhost:8532', 'tcp://localhost:8530' ]
227+
];
228+
```
229+
Using this option requires ArangoDB 3.3 or higher and the database running
230+
in active failover mode.
231+
232+
The driver will by default try to connect to the first server endpoint in the
233+
endpoints array, and only try the following servers if no connection can be
234+
established. If no connection can be made to any server, the driver will throw
235+
an exception.
236+
237+
As it is unknown to the driver which server from the array is the current
238+
leader, the driver will connect to the specified servers in array order by
239+
default. However, to spare a few unnecessary connection attempts to failed
240+
servers, it is possible to set up caching (using Memcached) for the server list.
241+
The cached value will contain the last working server first, so that as few
242+
connection attempts as possible will need to be made.
243+
244+
In order to use this caching, it is required to install the Memcached module
245+
for PHP, and to set up the following relevant options in the `ConnectionOptions`:
246+
247+
```php
248+
$connectionOptions = [
249+
// memcached persistent id (will be passed to Memcached::__construct)
250+
ConnectionOptions::OPTION_MEMCACHED_PERSISTENT_ID => 'arangodb-php-pool',
251+
252+
// memcached servers to connect to (will be passed to Memcached::addServers)
253+
ConnectionOptions::OPTION_MEMCACHED_SERVERS => [ [ '127.0.0.1', 11211 ] ],
254+
255+
// memcached options (will be passed to Memcached::setOptions)
256+
ConnectionOptions::OPTION_MEMCACHED_OPTIONS => [ ],
257+
258+
// key to store the current endpoints array under
259+
ConnectionOptions::OPTION_MEMCACHED_ENDPOINTS_KEY => 'arangodb-php-endpoints'
260+
261+
// time-to-live for the endpoints array stored in memcached
262+
ConnectionOptions::OPTION_MEMCACHED_TTL => 600
263+
];
264+
```
265+
266+
207267
<a name="creating_collection"></a>
208268
## Creating a collection
209269
*This is just to show how a collection is created.*

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
22
"name": "arangodb/arangodb",
33
"type": "library",
4-
"description": "ArangoDb PHP client",
5-
"keywords": ["database","ArangoDb","Arango","document store","NoSQL","multi-model","graph database"],
4+
"description": "ArangoDB PHP client",
5+
"keywords": ["database","ArangoDB","Arango","document store","NoSQL","multi-model","graph database","distributed"],
66
"homepage": "https://github.com/arangodb/arangodb-php",
77
"license": "Apache-2.0",
88
"authors": [

examples/init.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,23 @@
1616

1717
// normal unencrypted connection via TCP/IP
1818
ConnectionOptions::OPTION_ENDPOINT => 'tcp://localhost:8529', // endpoint to connect to
19+
20+
// // to use failover (requires ArangoDB 3.3 and the database running in active/passive failover mode)
21+
// // it is possible to specify an array of endpoints as follows:
22+
// ConnectionOptions::OPTION_ENDPOINT => [ 'tcp://localhost:8531', 'tcp://localhost:8532' ]
23+
24+
// // to use memcached for caching the currently active leader (to spare a few connection attempts
25+
// // to followers), it is possible to install the Memcached module for PHP and set the following options:
26+
// // memcached persistent id (will be passed to Memcached::__construct)
27+
// ConnectionOptions::OPTION_MEMCACHED_PERSISTENT_ID => 'arangodb-php-pool',
28+
// // memcached servers to connect to (will be passed to Memcached::addServers)
29+
// ConnectionOptions::OPTION_MEMCACHED_SERVERS => [ [ '127.0.0.1', 11211 ] ],
30+
// // memcached options (will be passed to Memcached::setOptions)
31+
// ConnectionOptions::OPTION_MEMCACHED_OPTIONS => [ ],
32+
// // key to store the current endpoints array under
33+
// ConnectionOptions::OPTION_MEMCACHED_ENDPOINTS_KEY => 'arangodb-php-endpoints'
34+
// // time-to-live for the endpoints array stored in memcached
35+
// ConnectionOptions::OPTION_MEMCACHED_TTL => 600
1936

2037
// // connection via SSL
2138
// ConnectionOptions::OPTION_ENDPOINT => 'ssl://localhost:8529', // SSL endpoint to connect to

0 commit comments

Comments
 (0)