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.
php-rdkafka extension (v5.0/6.0). Broadens applicability to environments where FFI is restricted or impractical (e.g., shared hosting, legacy systems). Still bypasses extension dependency for pure FFI users.php-rdkafka) reduces friction for hybrid architectures. Custom queue driver or wrapper layers still required for full Laravel integration.php-rdkafka in terms of feature parity (e.g., transactions, newer librdkafka versions), but retains FFI’s portability advantage. Tradeoff: FFI’s abstraction may still introduce overhead vs. native extension.php-rdkafka if FFI fails or is unavailable. Requires:
try FFI, catch -> use Extension).KafkaClientInterface).php-rdkafka compatibility simplifies custom driver development (e.g., leverage extension’s built-in queue features).FFI::new(), FFI::cast(), etc., may break custom wrappers relying on undocumented FFI patterns. Audit wrapper code for static FFI calls.pecl install).librdkafka support reduces version drift risk.config/kafka.php)?ShouldQueue logic?laravel/framework + this package.librdkafka versions (e.g., 2.5.3) to avoid breaking changes?librdkafka versions may introduce new metrics (e.g., transaction stats). Plan to expose these in Laravel’s observability?KafkaClient::produce() tries FFI, falls back to extension).pecl install rdkafka.'kafka' => [
'driver' => env('KAFKA_DRIVER', 'ffi'), // 'ffi' or 'extension'
'extension' => [
'enabled' => extension_loaded('rdkafka'),
],
],
interface KafkaClientInterface {
public function produce(string $topic, string $payload);
}
class FFIKafkaClient implements KafkaClientInterface { ... }
class ExtensionKafkaClient implements KafkaClientInterface { ... }
class KafkaClientFactory {
public function create(): KafkaClientInterface {
return extension_loaded('rdkafka') ? new ExtensionKafkaClient() : new FFIKafkaClient();
}
}
ShouldQueue to handle Kafka transactions:
class KafkaTransactionJob implements ShouldQueue {
public function handle() {
KafkaClient::transactional(function () {
// Job logic
});
}
}
php-rdkafka’s queue features to build a lightweight Kafka driver:
class KafkaQueue implements Queue {
public function push($job, $data, $queue = null) {
$this->client->produce($queue, json_encode($data));
}
public function pop($queue = null) {
return $this->client->consume($queue);
}
}
illuminate/queue.librdkafka features (e.g., dynamic metadata). Validate against target broker version.librdkafka transaction errors (e.g., ERR_TRANSACTION) to Laravel’s QueueException.librdkafka and php-rdkafka versions to avoid breaking changes (e.g., composer.json constraints).KafkaClientInterface).FFI::errno() and librdkafka logs.php-rdkafka’s existing debug tools.KafkaClient::getBackend()).librdkafka docs.php-rdkafka’s GitHub issues/Slack.php-rdkafka alone.kafka-consumer-groups CLI).queue:work --daemon --tries=3.php-rdkafka (e.g., php-benchmark).queue:work --batch=50).librdkafka 2.x reduces memory leaks. Monitor with kafka-consumer-perf-test.| Failure Scenario | Impact | Mitigation |
How can I help you explore Laravel packages today?