Download the PHP package mroosz/php-cassandra without Composer

On this page you can find all versions of the php package mroosz/php-cassandra. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package php-cassandra

php-cassandra: A modern Cassandra client for PHP

Latest Stable Version License PHP Version Require Total Downloads

Static Analysis: PHPStan Static Analysis: Psalm Tests: PHPUnit

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

Packagist: mroosz/php-cassandra
Repository: GitHub – MichaelRoosz/php-cassandra

Table of contents

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?

🚀 Modern Architecture

⚡ High Performance

🎯 Developer Friendly

Key Features

Requirements

System Requirements

Component Minimum Recommended Notes
PHP Version 8.1.0 8.3+ Latest stable version recommended
Architecture 32-bit/64-bit 64-bit 64-bit required for Bigint/Counter/Date/Duration/Time/Timestamp types and defaultTimestamp request option (unsupported on 32-bit)

PHP Extensions

Extension Required Purpose Notes
sockets Optional Socket transport Required for sockets connections configured with SocketNodeConfig
bcmath or gmp Optional Performance improvement for large integer operations Used by Varint and Decimal types
openssl Optional SSL/TLS connections Required for encrypted connections

Data Type Compatibility

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

Type 32-bit PHP 64-bit PHP Notes
Bigint ⚠️ Partial ✅ Full Supported if the value is within 32-bit range
Counter ⚠️ Partial ✅ Full Supported if the value is within 32-bit range
Date ❌ Unsupported ✅ Full Requires 64-bit PHP
Duration ❌ Unsupported ✅ Full Requires 64-bit PHP
Time ❌ Unsupported ✅ Full Requires 64-bit PHP
Timestamp ❌ Unsupported ✅ Full Requires 64-bit PHP

Additionally, the defaultTimestamp request option (in QueryOptions and BatchOptions) requires 64-bit PHP and is unsupported on 32-bit.

Installation

Using Composer (Recommended)

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

Without Composer

If you can't use Composer, you can load the library's own autoloader:

Quick start

Basic Connection and Query

Prepared statements

Async Operations Example

Error Handling Example

SSL/TLS Connection Example

Connecting

Create NodeConfig instances and pass them to Connection:

Connection options are provided via ConnectionOptions:

Keyspace selection:

Consistency levels

Use the Consistency enum:

Apply per call or as default via setConsistency().

Queries

Synchronous:

Asynchronous:

Query options (QueryOptions):

Notes:

Fetch all pages helpers:

Prepared statements

Pagination with prepared statements:

Execute all pages helper:

Additional notes:

Batches

Batch notes:

Results and fetching

query()/execute() return a Result; call asRowsResult() for row-returning queries. Supported RowsResult methods:

Example:

Advanced fetching examples:

Pagination example:

Object mapping

You can fetch rows into objects by implementing RowClassInterface or by using the default RowClass:

Data types

All native Cassandra types are supported via classes in Cassandra\Value\*. You may pass either:

Examples:

Type definition syntax for complex values

For complex types, the driver needs a type definition to encode PHP values. Wherever you see a parameter like \Cassandra\Type|(array{ type: \Cassandra\Type }&array<mixed>), you can either pass a scalar Type::... (for simple elements) or a definition array with nested types for complex structures. The common shapes are:

Examples

Nested complex example (Set inside a row):

Special values:

Events

Register a listener and subscribe for events on the connection:

Non-blocking event polling:

Tracing and custom payloads (advanced)

You can enable tracing and set a custom payload on any request:

Asynchronous API

The async API lets you pipeline multiple requests without blocking. Each async method returns a Cassandra\Statement handle that you can resolve later.

You now have both blocking and non-blocking control:

Basics:

Waiting for all responses:

Non-blocking draining and polling:

Prepared + async:

Advanced waiting:

Compression

Enable LZ4 compression (if supported by the server) via ConnectionOptions:

Notes:

Error handling

php-cassandra provides comprehensive error handling with a well-structured exception hierarchy. Understanding these exceptions helps you build robust applications with proper error recovery.

Exception Hierarchy

Error Handling Patterns

Basic Error Handling

Specific Server Error Handling

Retry Logic with Exponential Backoff

Timeout Handling

Error Information Access

Most server exceptions provide additional context:

Configuration Reference

Connection Configuration

Node Configuration

StreamNodeConfig (supports SSL/TLS, persistent connections)

SocketNodeConfig (requires ext-sockets)

Connection Options

Request Options

Query Options

Execute Options

Prepare Options

Batch Options

Advanced Configuration

Value Encoding Configuration

Event Listeners

Notes

Frequently Asked Questions (FAQ)

General Questions

Q: What's the difference between this library and the DataStax PHP Driver?

A: The main differences are:

Q: Can I use this with older versions of Cassandra?

A: Yes! The library supports protocol versions v3, v4, and v5:

Installation and Setup

Q: Do I need any PHP extensions?

A: The library works with standard PHP, but some extensions enhance functionality:

Q: Can I run this on 32-bit PHP?

A: Limited support. The following features are unsupported on 32-bit PHP: value types Bigint, Counter, Date, Duration, Time, Timestamp, and the defaultTimestamp request option. Use 64-bit PHP for full compatibility.

Data Types and Modeling

Q: How do I handle complex data structures?

A: Use collections and UDTs:

Q: How do I work with timestamps?

A: Use the Timestamp value class:

Migration Guide

From DataStax PHP Driver

If you're migrating from the DataStax PHP Driver, here are the key differences and migration steps:

Connection Setup

Query Execution

Prepared Statements

Data Types

Async Operations

Migration Checklist

Connection tuning examples

Configuring value encoding

Warnings listener

Event processing patterns

v5 keyspace per request

Tracing notes

Performance tips

Version support

API reference (essentials)

Changelog

See CHANGELOG.md for release notes and upgrade considerations.

License

This library is released under the MIT License. See LICENSE for details.

Contributing

Contributions are welcome! Here's how to get started:

Development Setup

  1. Fork and Clone

  2. Install Dependencies

  3. Start Development Environment

  4. Run Tests

Docker quickstart for integration tests:

Contribution Guidelines

Code Standards

Contributors

Special thanks to all contributors who have helped make this library better.

Supporting the Project

If you find this library useful, consider:

Your support helps keep this project active and improving!


All versions of php-cassandra with dependencies

PHP Build Version
Package Version
Requires php Version >=8.1
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package mroosz/php-cassandra contains the following files

Loading the files please wait ....