Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Home

mjpearson edited this page · 67 revisions
Clone this wiki locally

Pandra

Pandra (PHP-Cassandra) is a PHP based Thrift wrapper and domain model for Cassandra

Objects can be created on the fly from existing keyspaces or dynamic user data without requiring any kind of schema. However, it can happily enforce ColumnFamily/SuperColumn data models with key/column name and value validation.

TimeUUID, Long and String types are all supported.

Alongside the Cassandra and Thrift documentation mentioned, some required reading for those who are unfamiliar with Cassandra :

Data Model Support

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
**indicate schema aware Column Containers

Notations

Supports a range of programmatic notations in dealing with objectified multi-dimensional associative arrays
  • 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')

Connection handling

The ‘Core’ connection handler provides managed access to the underlying Cassandra/Thrift transports and API.

Core natively supports named connection pooling against Thrift’s TBinaryProtocol, TBinaryProtocolAccelerated and thrift_protocol.so, tweakable read/write modes (active connection, round-robin and random), dynamic consistency levels, robust logging and error correction 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.

Usage

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');
// discover and connect to a cluster via localhost
if (PandraCore::auto('localhost')) echo 'connected';
?>
Enabling the APC (Alternative PHP Cache) and Memcached (PECL) modules are suggested but not necessary, 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 a native PHP implementation. PECL and OSSP module based versions can also be imported from the pandra-contrib repository. They’ll be detected automatically.

When upgrading Cassandra to a newer version than what’s supported by Pandra, remember to regenerate the Thrift interface. Any new functionality will then be available via the PandraCore::getClient(); call.

$ thrift —gen php:oop -o {/path/to/pandra}/lib/thrift/packages/cassandra cassandra.thrift

The cassndra.thrift file is found in the /interfaces directory of the Cassandra package.

Examples

See Examples or Unit Tests for the latest snapshot . Both will be updated in place as additional features or fixes are applied.

Something went wrong with that request. Please try again.