DataStax Developer Blog

PHP Driver beta release

By Bulat Shakirzyanov -  May 27, 2015 | 0 Comments

Good day PHPhellows!

Today, I’m excited to announce the very first beta release of the DataStax PHP Driver for Apache Cassandra and DataStax Enterprise.

For too long, PHP developers like yourself had to access Apache Cassandra through the legacy Thrift interface. With the DataStax PHP Driver, finally, the wait is over, full power of Apache Cassandra and CQL is accessible directly in your PHP applications.

This release of the DataStax PHP Driver for Apache Cassandra and DataStax Enterprise includes the following features:

It’s been several weeks since we’ve released the alpha and while we’ve kept the API the same, all code has been moved directly into the extension. This means no autoloading is necessary once you’ve installed and enabled the extension.


To give you a taste of the new driver’s API, let me show you how to find all the members of a given Apache Cassandra cluster.


$cluster   = Cassandra::cluster()
$session   = $cluster->connect("system");
$statement = new Cassandra\SimpleStatement("SELECT * FROM local");
$host      = $session->execute($statement)->first();
$statement = new Cassandra\SimpleStatement("SELECT * FROM peers");
$peers     = $session->execute($statement);

sprintf("Current host's id is %s\n", (string) $host['host_id']);

foreach ($peers as $peer) {
    sprintf("Host %s has IP %s\n", (string) $host['host_id'], (string) $host['peer']);

Check out Cassandra\Cluster\Builder API docs for more details on cluster configuration and Cassandra\Session API docs to learn how to execute statements.

My favorite feature of the PHP driver is its first class support for asynchronous execution, which makes it very easy to parallelize statements execution:


$data = array(
    array(41, 'Sam'),
    array(35, 'Bob')

$statement = $session->prepare("UPDATE users SET age = ? WHERE user_name = ?");
$futures   = array();

// execute all statements in background
foreach ($data as $arguments) {
    $futures[]= $session->executeAsync($statement, new ExecutionOptions(
                    'arguments' => $arguments

// wait for all statements to complete
foreach ($futures as $future) {
    // we will not wait for each result for more than 5 seconds

Learn more about Cassandra\Future by reading its API docs.

This beta release has been a long time coming and includes many new features. Describing all of them here would make this post unbearably long. But we prepared docs that are detailing most of them.

We can’t wait to see what you build with it!


P.S. We would like to know more about your development/deployment environment to prioritize our testing infrastructure accordingly, please take a few minutes to complete the survey.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>