Configuring ArangoDB-PHP to use active failover
This article is about setting up active failover for ArangoDB-PHP, the PHP client driver for ArangoDB. It requires ArangoDB-PHP 3.3.2 or higher, and an ArangoDB server version of 3.3.4 or higher.
Interested in trying out ArangoDB? Fire up your cluster in just a few clicks with ArangoDB ArangoGraph: the Cloud Service for ArangoDB. Start your free 14-day trial here
Active failover: basic setup
Historically, ArangoDB-PHP has been able to connect to a single ArangoDB endpoint, i.e. one combination of IP address and port number.
To connect to an ArangoDB server that is running on localhost or on a remote server, simply set the `OPTION_ENDPOINT` item in the `ConnectionOptions` and connect: Read more
ArangoDB PHP Driver: Enhancements for Version 2.7
While preparing the release of ArangoDB 2.7, some improvements were made for the PHP driver for ArangoDB.
The 2.7 version of the PHP driver now supports the AQL query results cache. The cache can be turned on or off globally, or be set to demand mode. The demand mode will allow controlling caching on a per-AQL-query basis. Read more
Getting Started with ArangoDB & Symfony: Part 1 | ArangoDB 2013
In this tutorial we will implement a very simple movie database as an example of how to use ArangoDB together with Symfony 2. We assume for the tutorial that you know the basic concepts of Symfony2. No prior ArangoDB knowledge is required.
The demo shows how to create, edit, update and delete movies, how to select a list of movies from the database in two different ways. We’ll use the simple query API for most examples. The “search for a topic” feature uses ArangoDB’s query language (AQL), a convenient sql-like way to query ArangoDB.
You can download the completed demo at Github.
A short word on ArangoDB
Warning - a paragraph of marketing ahead! ;-) ArangoDB is an open-source mostly-memory database with a flexible data model for documents and graphs for modern web applications. With ArangoDB you build high performance applications in short time - it is schema-less and has a full-blown query language nevertheless (there is no need to write map/reduce functions if your queries get more complicate) . You can even extend ArangoDB by adding your own Javascript/Ruby methods to the database.
Libraries & infrastructure
The following components are used
- ArangoDB 1.2 (installable via one-click-installers for many operating systems)
- Symfony 2.2
- the ArangoDB PHP driver
- the MopArangoDbBundle
What’s this? Since Symfony is a PHP framework we need the PHP driver for ArangoDB. The MopArangoDbBundle integrates the PHP driver into Symfony: having this bundle installed, you can config the connection to ArangoDB in the config.yml (note: the bundle also offers a FOSUserBundle integration which is not used in this demo, but might be interested for you if you are looking for a user management system out of the box).
Installing ArangoDB
Now grab your copy of ArangoDB from the download page and install it. There are binaries available for many common platforms (Linux, OSX, Windows). Make sure that ArangoDB is up and running by opening the graphical user interface in your browser:
http://localhost:8529/_admin/html/index.html
Configuring Symfony for use with ArangoDB
First thing we have to do is to tell Symfony that we want to work with ArangoDB. So we add the two required bundles to composer.json and run “php composer.phar update” as usual.
// path/to/myapp/composer.json
"require": {
…
"triagens/ArangoDb": "dev-devel",
"mop/arangodbbundle" : "dev-master"
…
},
Note: for this tutorial a feature was added to the ArangoDB PHP driver which is only available in the “dev-devel” branch at the time of writing this text.
Having MopArangodbBundle installed we can add our connection settings to config.yml
//myapp/app/config/config.yml
mop_arango_db:
default_connection: main #will be set to the first connection if not present
connections:
main:
host: 127.0.0.1
port: 8529
We are done.
In Symfony we can now access the default connection to ArangoDB with
$connection = $this->get('mop_arangodb.default_connection');
The end
Congrats, you have reached the end of part 1 the tutorial. There is more:
- Symfony 2 & ArangoDB - part 1: setup and getting a connection
- Symfony 2 & ArangoDB - part 2: data modelling & fetching a list from the DB
- Symfony 2 & ArangoDB - part 3: working with forms & data transformers
- Symfony 2 & ArangoDB - part 4: extending ArangoDB Document & querying via AQL
ArangoDB & Symfony Integration: Part 2 | ArangoDB ’13
You can download the completed demo at Github.
The data structure
Our app deals with movies: each movie has a title, a year of release and it is assigned to a genre. Each movie deals with none, one or many topics.
In a relational database we would probably create a table movie and another table topic and join them with a shared movie id.
ArangoDB follows like other document stores the “aggregate model” approach: In short terms this means that you should put data that is often needed together into one document. Remember: documents are a bit like rows in the relation world; in nosql world they can have a nested structure.
ArangoDB & Symfony Integration: Part 3 Guide | ArangoDB ’13
You can download the completed demo at Github.
Working with forms
The next example shows the use of ArangoDB with Symfony’s form component.
This is how our form will look like. The topics are represented as a text field and the user is required to separate them by commas. This delivers questionable user experience, but leads to an interesting question: how can we transform our topics array from our movie document to a text field? And: we’ll need it at least two times, both for creating and editing movies.
ArangoDB & Symfony Integration: Part 4 Guide | ArangoDB ’13
You can download the completed demo at Github.
Extending Arangodb\Document
The next thing we want to improve are all those noisy set calls in the controller:
// src/Triagens/ArangodbBundle/Controller/DefaultController.php
if ($form->isValid()) {
$movie = new ArangoDocument();
$movie->set("title",$form->get("title")->getData());
$movie->set("released",$form->get("released")->getData());
$movie->set("genre",$form->get("genre")->getData());
// and so on ... my eyes hurt!
}
Get the latest tutorials,
blog posts and news:
Thanks for subscribing! Please check your email for further instructions.