PHP port of Twitter's flockdb-client for connecting to FlockDB instances
Obtain a copy of the thrift php library, any version will do.
If you already have the thrift library in place, use it.
You will need to copy thrift/packages/FlockDB
to your own thrift packages
directory.
For those lacking, I've made the library available in the thrift
directory.
Or if you prefer going to the source, download it from Apache Thrift
and copy thrift/packages/FlockDB
into the fresh download.
Set the THRIFT_ROOT:
$GLOBALS['THRIFT_ROOT'] = '/location/of/thrift/php/lib';
Include the Phlock library. Easiest is to use the supplied autoload.php
:
require_once 'phlockdb-client/src/autoload.php';
Instantiate a connection to FlockDB:
$flock = new Phlock(array('127.0.0.1:7915'), array('graphs'=>array('follows'=>1, 'blocks'=>2)));
Edge manipulation:
$flock->add(1, 'follows', 2);
$flock->remove(1, 'blocks', 2);
Queries can be paginated:
$cursor = $flock->select(1, 'follows', null);
$page1 = $cursor->currentPage();
print_r($page1);
if ($cursor->hasNextPage()) {
$cursor->nextPage();
$page2 = $cursor->currentPage();
print_r($page2);
}
Or iterated:
$cursor = $flock->select(1, 'follows', null);
$following = iterator_to_array($cursor, false);
This project is in its infancy. Here is a list of things outstanding today.
-
Let the thrift client accept multiple servers for failover.
-
Allow optional client settings like timeout and buffer size.
-
Cursor pagination features: prev page, and native Iterator support.
-
This:
flockdb.select(nil, :follows, 1).difference(flockdb.select(1, :follows, nil).intersect(2, :follows, nil)).to_a