|
22 | 22 | - [Cloning the git repository](#cloning_git)
|
23 | 23 | - [How to use the PHP client](#howto_use)
|
24 | 24 | - [Setting up the connection options](#setting_up_connection_options)
|
| 25 | + - [Setting up failover](#setting_up_failover) |
25 | 26 | - [Creating a collection](#creating_collection)
|
26 | 27 | - [Creating a document](#creating_document)
|
27 | 28 | - [Adding exception handling](#adding_exception_handling)
|
@@ -204,6 +205,65 @@ When updating a document that was previously/concurrently updated by another use
|
204 | 205 | * fail with a conflict error: if you prefer that, set OPTION_UPDATE_POLICY to conflict
|
205 | 206 |
|
206 | 207 |
|
| 208 | +<a name="setting_up_failover"></a> |
| 209 | +## Setting up 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/passive 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 | + |
207 | 267 | <a name="creating_collection"></a>
|
208 | 268 | ## Creating a collection
|
209 | 269 | *This is just to show how a collection is created.*
|
|
0 commit comments