PHPackages                             mroosz/php-cassandra - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. mroosz/php-cassandra

ActiveLibrary[Database &amp; ORM](/categories/database)

mroosz/php-cassandra
====================

A pure-PHP client for Apache Cassandra and ScyllaDB with support for CQL binary protocol v3, v4 and v5 (Cassandra 2.1+ incl. 3.x-5.x; ScyllaDB 6.2 and 2025.x), synchronous and asynchronous APIs, prepared statements, batches, result iterators, object mapping, SSL/TLS, and LZ4 compression.

v1.2.0(7mo ago)217.4k↓23.2%33MITPHPPHP &gt;=8.1CI passing

Since Mar 19Pushed 5mo ago4 watchersCompare

[ Source](https://github.com/MichaelRoosz/php-cassandra)[ Packagist](https://packagist.org/packages/mroosz/php-cassandra)[ Docs](https://github.com/MichaelRoosz/php-cassandra)[ RSS](/packages/mroosz-php-cassandra/feed)WikiDiscussions main Synced 3d ago

READMEChangelog (10)Dependencies (6)Versions (13)Used By (3)

php-cassandra: A modern Cassandra client for PHP
================================================

[](#php-cassandra-a-modern-cassandra-client-for-php)

[![Latest Stable Version](https://camo.githubusercontent.com/5ce369ea441547c22fb453c52a6bf2a2903104f8c69bb80e13b7763c9b53a561/68747470733a2f2f706f7365722e707567782e6f72672f6d726f6f737a2f7068702d63617373616e6472612f762f737461626c65)](https://packagist.org/packages/mroosz/php-cassandra)[![License](https://camo.githubusercontent.com/b4e9b5eecdbdbe1725924987779df86fc1e4f205a0c18d69830530b52c565b37/68747470733a2f2f706f7365722e707567782e6f72672f6d726f6f737a2f7068702d63617373616e6472612f6c6963656e7365)](https://packagist.org/packages/mroosz/php-cassandra)[![PHP Version Require](https://camo.githubusercontent.com/3153c6450cc74186120490064ff584fb501fda4275d07d4666f003ec47f85459/68747470733a2f2f706f7365722e707567782e6f72672f6d726f6f737a2f7068702d63617373616e6472612f726571756972652f706870)](https://packagist.org/packages/mroosz/php-cassandra)[![Total Downloads](https://camo.githubusercontent.com/65e3efea082957a7d0e0413a3d218b9fcd0f647c881bc87027b9d617b033a05a/68747470733a2f2f706f7365722e707567782e6f72672f6d726f6f737a2f7068702d63617373616e6472612f646f776e6c6f616473)](https://packagist.org/packages/mroosz/php-cassandra)

[![Static Analysis: PHPStan](https://camo.githubusercontent.com/73c7e2a3375d6bac20cc527599c7c4bdf5b9d75c40d5d07cab5fcd2eba1ef137/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f537461746963253230616e616c797369732d5048505374616e2d3165393066663f6c6f676f3d7068707374616e266c6f676f436f6c6f723d7768697465)](https://phpstan.org)[![Static Analysis: Psalm](https://camo.githubusercontent.com/357c3496c54ee3e781ae0d3973de583aff1269c65cb130ea7878d85e1f15accf/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f537461746963253230616e616c797369732d5073616c6d2d3441343142453f6c6f676f3d7073616c6d266c6f676f436f6c6f723d7768697465)](https://psalm.dev)[![Tests: PHPUnit](https://camo.githubusercontent.com/931c7ecf7c89104464aa4e4ebe76ee94d6219e8bca500d00abd906a9dd36b58c/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f54657374732d504850556e69742d3643373841463f6c6f676f3d706870756e6974266c6f676f436f6c6f723d7768697465)](https://phpunit.de)

php-cassandra is a pure-PHP client for Apache Cassandra and ScyllaDB with support for CQL binary protocol v3, v4 and v5 (Cassandra 2.1+ incl. 3.x–5.x; ScyllaDB 6.2 and 2025.x), synchronous and asynchronous APIs, prepared statements, batches, result iterators, object mapping, SSL/TLS, and LZ4 compression.

**Packagist:** [mroosz/php-cassandra](https://packagist.org/packages/mroosz/php-cassandra)
**Repository:** [GitHub – MichaelRoosz/php-cassandra](https://github.com/MichaelRoosz/php-cassandra)

Table of contents
-----------------

[](#table-of-contents)

- [php-cassandra: A modern Cassandra client for PHP](#php-cassandra-a-modern-cassandra-client-for-php)
    - [Table of contents](#table-of-contents)
    - [Introduction](#introduction)
        - [Why choose php-cassandra?](#why-choose-php-cassandra)
        - [Key Features](#key-features)
    - [Requirements](#requirements)
        - [System Requirements](#system-requirements)
        - [PHP Extensions](#php-extensions)
        - [Data Type Compatibility](#data-type-compatibility)
    - [Installation](#installation)
        - [Using Composer (Recommended)](#using-composer-recommended)
        - [Without Composer](#without-composer)
    - [Quick start](#quick-start)
        - [Basic Connection and Query](#basic-connection-and-query)
        - [Prepared statements](#prepared-statements)
        - [Async Operations Example](#async-operations-example)
        - [Error Handling Example](#error-handling-example)
        - [SSL/TLS Connection Example](#ssltls-connection-example)
    - [Connecting](#connecting)
    - [Consistency levels](#consistency-levels)
    - [Queries](#queries)
    - [Prepared statements](#prepared-statements-1)
    - [Batches](#batches)
    - [Results and fetching](#results-and-fetching)
    - [Object mapping](#object-mapping)
    - [Data types](#data-types)
    - [Type definition syntax for complex values](#type-definition-syntax-for-complex-values)
    - [Events](#events)
    - [Tracing and custom payloads (advanced)](#tracing-and-custom-payloads-advanced)
    - [Asynchronous API](#asynchronous-api)
    - [Compression](#compression)
    - [Error handling](#error-handling)
        - [Exception Hierarchy](#exception-hierarchy)
        - [Error Handling Patterns](#error-handling-patterns)
            - [Basic Error Handling](#basic-error-handling)
            - [Specific Server Error Handling](#specific-server-error-handling)
            - [Retry Logic with Exponential Backoff](#retry-logic-with-exponential-backoff)
            - [Timeout Handling](#timeout-handling)
        - [Error Information Access](#error-information-access)
    - [Configuration Reference](#configuration-reference)
        - [Connection Configuration](#connection-configuration)
            - [Node Configuration](#node-configuration)
            - [Connection Options](#connection-options)
        - [Request Options](#request-options)
            - [Query Options](#query-options)
            - [Execute Options](#execute-options)
            - [Prepare Options](#prepare-options)
            - [Batch Options](#batch-options)
        - [Advanced Configuration](#advanced-configuration)
            - [Value Encoding Configuration](#value-encoding-configuration)
            - [Event Listeners](#event-listeners)
    - [Notes](#notes)
    - [Frequently Asked Questions (FAQ)](#frequently-asked-questions-faq)
        - [General Questions](#general-questions)
        - [Installation and Setup](#installation-and-setup)
        - [Data Types and Modeling](#data-types-and-modeling)
    - [Migration Guide](#migration-guide)
        - [From DataStax PHP Driver](#from-datastax-php-driver)
            - [Connection Setup](#connection-setup)
            - [Query Execution](#query-execution)
            - [Prepared Statements](#prepared-statements-2)
            - [Data Types](#data-types-1)
            - [Async Operations](#async-operations)
        - [Migration Checklist](#migration-checklist)
    - [Connection tuning examples](#connection-tuning-examples)
    - [Configuring value encoding](#configuring-value-encoding)
    - [Warnings listener](#warnings-listener)
    - [Event processing patterns](#event-processing-patterns)
    - [v5 keyspace per request](#v5-keyspace-per-request)
    - [Tracing notes](#tracing-notes)
    - [Performance tips](#performance-tips)
    - [Benchmarks](#benchmarks)
    - [Version support](#version-support)
        - [Server compatibility and required settings](#server-compatibility-and-required-settings)
    - [API reference (essentials)](#api-reference-essentials)
    - [Changelog](#changelog)
    - [License](#license)
    - [Contributing](#contributing)
        - [Development Setup](#development-setup)
        - [Contribution Guidelines](#contribution-guidelines)
            - [Code Standards](#code-standards)
        - [Contributors](#contributors)
        - [Supporting the Project](#supporting-the-project)

Introduction
------------

[](#introduction)

php-cassandra is a modern PHP client for Apache Cassandra that prioritizes **correctness**, **performance**, and **developer experience**. This library aims to provide full protocol coverage and advanced features while maintaining simplicity.

### Why choose php-cassandra?

[](#why-choose-php-cassandra)

**🚀 Modern Architecture**

- Pure PHP implementation with no external dependencies
- Support for latest Cassandra protocol versions (v3/v4/v5)
- Built for PHP 8.1+ with modern language features

**⚡ High Performance**

- Asynchronous request pipelining for maximum throughput
- LZ4 compression support for reduced bandwidth
- Prepared statement caching and reuse

**🎯 Developer Friendly**

- Complete data type coverage including complex nested structures
- Rich configuration options with sensible defaults
- Object mapping with customizable row classes

### Key Features

[](#key-features)

- **Protocol Support**: v3/v4/v5 with automatic negotiation
- **Transports**: Sockets and PHP streams (SSL/TLS, persistent connections)
- **Request Types**: Synchronous, Asynchronous
- **Statements**: Prepared statements with positional/named binding, auto-prepare
- **Data Types**: Full coverage including collections, tuples, UDTs, custom types, vectors
- **Results**: Iterators, multiple fetch styles, object mapping
- **Events**: Schema/status/topology change notifications
- **Advanced**: LZ4 compression, server overload signaling, tracing support

Requirements
------------

[](#requirements)

### System Requirements

[](#system-requirements)

ComponentMinimumRecommendedNotes**PHP Version**8.1.08.3+Latest stable version recommended**Architecture**32-bit/64-bit64-bit64-bit required for Bigint/Counter/Date/Duration/Time/Timestamp types and defaultTimestamp request option (unsupported on 32-bit)### PHP Extensions

[](#php-extensions)

ExtensionRequiredPurposeNotes**sockets**OptionalSocket transportRequired for sockets connections configured with `SocketNodeConfig`**bcmath** or **gmp**OptionalPerformance improvement for large integer operationsUsed by `Varint` and `Decimal` types**openssl**OptionalSSL/TLS connectionsRequired for encrypted connections### Data Type Compatibility

[](#data-type-compatibility)

Some Cassandra data types require 64-bit PHP and are unsupported on 32-bit:

Type32-bit PHP64-bit PHPNotes`Bigint`⚠️ Partial✅ FullSupported if the value is within 32-bit range`Counter`⚠️ Partial✅ FullSupported if the value is within 32-bit range`Date`❌ Unsupported✅ FullRequires 64-bit PHP`Duration`❌ Unsupported✅ FullRequires 64-bit PHP`Time`❌ Unsupported✅ FullRequires 64-bit PHP`Timestamp`❌ Unsupported✅ FullRequires 64-bit PHPAdditionally, the `defaultTimestamp` request option (in `QueryOptions` and `BatchOptions`) requires 64-bit PHP and is unsupported on 32-bit.

Installation
------------

[](#installation)

### Using Composer (Recommended)

[](#using-composer-recommended)

```
composer require mroosz/php-cassandra
```

Then include Composer's autoloader in your application entrypoint (if not already):

```
