-
Notifications
You must be signed in to change notification settings - Fork 11
Home
Pandra (PHP-Cassandra) is a light weight, flexible PHP based CRUD extension for Cassandra / Thrift suitable for object relational models or factory design patterns.
Pandra objects can be created on the fly from existing keyspaces or dynamic user data without requiring any kind of schema. However, it will happily enforce ColumnFamily/SuperColumn schemas and validate column values where needed with minimal overhead.
Alongside the Cassandra and Thrift documentation mentioned, some required reading for those who are unfamiliar with Cassandra :
- WTF is a SuperColumn
- up and running with Cassandra
- Building a small Cassandra cluster for testing and development
Pandra supports data structures up to the 5th dimensionality provided by Cassandra. From the bottom up, supported data types, their classful implementation name and their (conceptual) RDBMS analogues consist of the following -
Cassandra | Pandra | Description | RDBMS |
---|---|---|---|
Column | Column | The atomic data type in Cassandra space, consisting of 3 attributes – a name-value pair and a (last modified) timestamp. | Column |
Column Family | ColumnFamily** | A named associative array container of Columns. Column Familes may only have a Key parent. | Table |
Super Column | SuperColumn** | Practically identical to a Column Family, however has a Super Column Family as parent. Multiple Super Columns can exist for a key, in a (Super) Column Family | Table |
Super Column Family | SuperColumnFamily** | A Super Column container, having a Key parent. | Table of Tables |
Key ID | $keyID (string, container attribute) | The unique key for the record. All data for a single key/columfamily must fit on a single node | Primary Key |
Key Space | $keySpace (string, container attribute) | Top level container for Column Families and their underlying Keys. | Database |
- Natural associative arrays, eg:
$cfSuper['superName']['columnName'] = 'foo'
- Chained magic methods, eg:
$cfSuper->super_superName->column_columnName = 'foo'
- Chained mutators (IDE auto-complete friendly), eg:
$cfSuper->getSuper('superName')->getColumn('columnName')->setValue('foo')
The ‘Core’ connection handler provides managed access to the underlying Cassandra/Thrift transports and API.
Core natively supports named transports against Thrift’s TBinaryProtocol, TBinaryProtocolAccelerated and thrift_protocol.so, tweakable read/write modes (active connection, round-robin and random), dynamic consistency levels and a complete abstraction suite against the Thrift API. It’s therefore straight forward to create your own data model without any reliance on the packaged ColumnContainer classes.
As of 0.2 support will be introduced for named connection pooling, node auto-discovery, APC/Memcached round-robin or temporal ‘key-active’ (MODE_ACTIVE in 0.1, with an extra key/CF binding) modes, configurable node timeouts and retry intervals, robust logging, and consistency downgrading.
Pandra comes bundled with everything it needs to start talking to Cassandra right away. After downloading the source, simply include the config.php and it will take care of the rest.<?php require_once('/path/to/pandra/config.php'); if (PandraCore::connect('default', 'localhost')) echo 'connected'; ?>Enabling the APC (Alternative PHP Cache) module is suggested, clients on 64-bit machines can also make use of the thrift_protocol.so module for best performance :
$ cd /path/to/pandra/thrift-php/ext/thrift_protocol $ phpize $ ./configure $ make $ cp modules/thrift_protocol.so /path/to/php/modules… update php.ini to include the new thrift_protocol.so, then restart Apache/nginx etc.
Time and Lexical UUID’s are supported by the very efficient OSSP PHP-UUID module (php5-uuid for debian/ubuntu users). Check lib/ext/UUID.class.php if you’d like to swap it out for your own implementation.
See Examples or Unit Tests for the latest snapshot . Both will be updated in place as additional features or fixes are applied.