Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message
Php Rdkafka Ffi

Php Rdkafka Ffi Laravel Package

idealo/php-rdkafka-ffi

Unmaintained Kafka client for PHP 7.4–8.0 using FFI bindings to librdkafka, compatible with php-rdkafka interfaces. Supports producer (transactions), consumer, admin client, mock cluster for tests, and callback-based error/log handling.

View on GitHub
Deep Wiki
Context7

PHP Kafka client - binding librdkafka via FFI

Frequently asked questions about Php Rdkafka Ffi
Can I use this package directly in Laravel without a custom queue driver?
No, this package doesn’t integrate natively with Laravel’s queue system. You’ll need to wrap it in a custom queue driver (e.g., `KafkaQueue`) or use it alongside Laravel’s job system for async processing. The package provides the low-level Kafka client, but integration requires manual setup.
How do I choose between FFI and the php-rdkafka extension in Laravel?
Use FFI for portability (no extension compilation) or shared hosting, and the extension for performance. The package supports both via conditional logic: detect `extension_loaded('rdkafka')` and instantiate the appropriate client. Example: `new (extension_loaded('rdkafka') ? ExtensionKafkaClient : FFIKafkaClient)()`.
Will this work with Laravel 11 (PHP 8.3+) despite the PHP 8.0 max version?
Officially, the package targets PHP 8.0, but it may work with PHP 8.3/8.4 if you disable `zend.max_allowed_stack_size` (set to `-1` in `php.ini`) due to FFI callback limitations. Test thoroughly with Laravel 11’s PHP 8.2+ dependencies, as some edge cases (e.g., stack overflow) may arise.
How do I handle Kafka transactions in Laravel queue jobs to avoid duplicate processing?
Use the package’s transactional producer with `KafkaProducer::beginTransaction()` and `commit()`/`abort()`. For Laravel jobs, wrap transaction logic in a `ShouldQueue` job with retry logic. If a transaction fails, mark the job as failed in Laravel’s queue table to prevent reprocessing. Test with the mock cluster to simulate errors.
Is there a way to mock Kafka for Laravel unit tests without a real cluster?
Yes, the package includes a `MockCluster` class to simulate Kafka topics, producers, and consumers. Use it in tests by replacing the real client with the mock during test setup. Example: `$kafka = new MockCluster(); $this->app->bind(KafkaClientInterface::class, fn() => $kafka);`.
What librdkafka versions are supported, and how do I pin a specific version?
The package supports librdkafka 2.1.0–2.8.0. Pin a version by installing the matching system library (e.g., `librdkafka-dev`) and configuring your build environment. Avoid newer versions unless explicitly tested, as breaking changes may occur. Check the [librdkafka changelog](https://github.com/confluentinc/librdkafka/blob/master/CHANGELOG.md) for compatibility.
How do I configure dual-mode (FFI + extension) in Laravel’s config?
Add a `kafka` config key with a `driver` option (e.g., `'driver' => env('KAFKA_DRIVER', 'ffi')`). Use a factory to instantiate the correct client: `return extension_loaded('rdkafka') ? new ExtensionKafkaClient(config('kafka')) : new FFIKafkaClient(config('kafka'));`. Example config: `kafka.php` with `extension` and `ffi` subarrays for shared settings.
Are there performance differences between FFI and the php-rdkafka extension?
Yes, the native extension is faster due to lower overhead. FFI adds ~10–30% latency for operations like producing/consuming messages, but the difference is negligible for most high-throughput use cases. Benchmark your workload: FFI is ~50–100ms per 10K messages; the extension is ~20–50ms. Use the extension for critical paths.
How do I handle errors or log messages from Kafka in Laravel’s logging system?
Use the package’s callback-based error/logging system. Register callbacks via `KafkaClient::setErrorCallback()` and `setLogCallback()`, then forward logs to Laravel’s `Log` facade. Example: `$client->setLogCallback(fn($level, $facility, $message) => Log::channel('kafka')->debug($message));`.
What alternatives exist for Kafka in Laravel if this package is unmaintained?
Consider the official `php-rdkafka` extension (PECL) for production, or modern alternatives like `rbdsh/kafka-php` (pure PHP, no FFI) or `confluentinc/confluent-kafka-php` (official Confluent client). For Laravel, also evaluate `spatie/laravel-kafka` (wrapper for `php-rdkafka`) or `laravel-kafka` (community-driven).
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
emuniq/filament-browser-notifications
syriable/filament-translator
hungnm28/livewire-form
wenprise/eloquent
crudly/encrypted
fadion/bouncy
cuci/prototurk-sdk
gos/pubsub-router-bundle
cuci/prototurk-sdk-symfony
clementtalleu/easyadmin-markdown-bundle
codeflextech/permission-manager
karnoweb/livewire-datepicker
sayedenam/sayed-dashboard
milito/query-filter
apiboxsym/user-bundle
apiboxsym/health-check-bundle
jayeshmepani/jpl-moshier-ephemeris-php
elnasnato/laraliveui
labrodev/rest-sdk
sampaui/sampaui