phpthriftcassandra-2.0datastaxdatastax-php-driver

Thrift + Cassandra + PHP + Windows?


Connecting to Cassandra with PHP is really a pain. The documentations at Apache and DataStax are extremely poorly written - for Windows users.

I have Thrift installed (I believe!) via Chocolatey. But I am still not able to compile php code for Cassandra using thrift.

If you look at this link ,

  1. now we can compile php code for Cassandra using thrift I used command: d:\cassandra\trift\thrift.exe --gen php d:\cassandra\interface\cassandra.thrift

So what is cassandra.thrift and where does it come from?? WHAT should I put inside it??

If I follow the instruction exactly, I get this error,

Could not open input file: d:\cassandra\interface\cassandra.thrift

enter image description here

So what is going on?

How do I make this work?

I have tried to install DataStax PHP Driver for Apache Cassandra and that documentation even worst.

Why PHP modules do not come with Cassandra like it does for MongoDB? Most of the independent drivers I found are outdated, not supported anymore or abandoned.

EDIT:

From the README,

Install the PHP extension

Installing with pecl

The PHP driver is not published to the official PECL repository yes. You can still install it using pecl by specifying the provided package.xml file path as the argument to pecl install command.

Install the 2.0 version of the C/C++ driver

not published to the official PECL repository yes - is it yes or yet?

Obtaining Build Dependencies

CMake
Git
ActiveState Perl
Python v2.7.x

I have downloaded and installed. Then, what? In Building the Driver,

A batch script has been created to detect installed versions of Visual...

What? Where does A batch script suddenly come from??

Then,

First you will need to open a “Command Prompt” (or Windows SDK Command Prompt) to execute the batch script.

Usage: VC_BUILD.BAT [OPTION...]

--DEBUG                           Enable debug build
--RELEASE                         Enable release build (default)
--DISABLE-CLEAN                   Disable clean build

....

What are these bunch of '--' for?

To build 32-bit shared library:

VC_BUILD.BAT --X86 To build 64-bit shared library:

VC_BUILD.BAT --X64

Where does .BAT come from? What should I put inside it? Where should I run it from??

After all, what are those Build Dependencies for? How do I use them??

Just hope that someone can write a proper guide then the guide above - it is frightening! (if you compare the guides in MongoDB, it is far better and professional)

EDIT 2:

First error when I run the .bat from my desktop,

enter image description here

I have git installed already but I still have this error,

enter image description here

After fixing git issue above, I have a new one - it just frozen there, nothing happens,

enter image description here


Solution

  • Forget about Thrift and the 'beta', I found a better solution. It very straight forward and extremely easy!

    Example codes,

    require_once 'lib/Cassandra/Cassandra.php';
    
    $cassandra = new Cassandra();
    
    $s_server_host     = '127.0.0.1';    // Localhost
    $i_server_port     = 9042;
    $s_server_username = 'admin';  // We don't use username
    $s_server_password = 'password';  // We don't use password
    $s_server_keyspace = 'demo';  // We don't have created it yet
    
    $cassandra->connect($s_server_host, $s_server_username, $s_server_password, $s_server_keyspace, $i_server_port);
    
    // Tests if the connection was successful:
    if ($cassandra) {
    
        // Select:
        // Queries a table.
        $cql = "SELECT * FROM users;";
    
        // Launch the query.
        $results = $cassandra->query($cql);
    
        // Update:
        // Prepares a statement.
        $stmt = $cassandra->prepare('UPDATE users SET first_name = ?, last_name = ? where id = ?');
    
        // Executes a prepared statement.
        $values = array('first_name' => 'Fred', 'last_name' => 'Smith', 'id' => '1');
        $result = $cassandra->execute($stmt, $values);
    
        // Insert:
        // Prepares a statement.
        $stmt = $cassandra->prepare('INSERT INTO users (id, first_name, last_name)
        VALUES (:id, :first_name, :last_name)');
    
        // Executes a prepared statement.
        $values = array('first_name' => 'John', 'last_name' => 'Robinson', 'id' => '4');
        $result = $cassandra->execute($stmt, $values);
    
        // Delete:
        // Prepares a statement.
        $stmt = $cassandra->prepare('DELETE FROM users WHERE id = :id');
    
        // Executes a prepared statement.
        $values = array('id' => '4');
        $result = $cassandra->execute($stmt, $values);
    
        // Closes the connection.
        $cassandra->close();
    }