https://github.com/leocavalcante/kafka-phplayground
🎸 Just some fun with Kafka, PHP and Swoole
https://github.com/leocavalcante/kafka-phplayground
example kafka php swoole
Last synced: over 1 year ago
JSON representation
🎸 Just some fun with Kafka, PHP and Swoole
- Host: GitHub
- URL: https://github.com/leocavalcante/kafka-phplayground
- Owner: leocavalcante
- License: mit
- Created: 2020-10-17T15:44:17.000Z (almost 6 years ago)
- Default Branch: main
- Last Pushed: 2020-10-19T17:33:50.000Z (almost 6 years ago)
- Last Synced: 2025-03-29T22:41:19.028Z (over 1 year ago)
- Topics: example, kafka, php, swoole
- Language: PHP
- Homepage:
- Size: 304 KB
- Stars: 19
- Watchers: 5
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Kafka PHPlayground
🎸 Just some fun with [Kafka](https://kafka.apache.org/), [PHP](https://www.php.net/) and [Swoole](https://www.swoole.co.uk/).
> Apache Kafka is an open-source distributed event streaming platform used by thousands of companies for high-performance data pipelines, streaming analytics, data integration, and mission-critical applications.
> Swoole is a Coroutine based Async PHP Programming Framework to Build high-performance, scalable, concurrent TCP, UDP, Unix Socket, HTTP, WebSocket services with PHP and fluent Coroutine API.
## Requirements
- PHP >= 7.4 (https://launchpad.net/~ondrej/+archive/ubuntu/php)
- Swoole >= 4.5 (https://www.swoole.co.uk/docs/get-started/installation)
- Java >= 8 (https://openjdk.java.net/install/)
## Instructions
### Kafka
- Download it from https://kafka.apache.org/downloads
- Extract to `/kafka`
- `test -f kafka/bin/kafka-server-start.sh && echo OK` (should print `OK`).
#### Start the services
- `kafka/bin/zookeeper-server-start.sh kafka/config/zookeeper.properties`
- `kafka/bin/kafka-server-start.sh kafka/config/server.properties`
#### Create a topic
- `kafka/bin/kafka-topics.sh --create --topic my-topic --bootstrap-server localhost:9092`
- `Created topic my-topic.` should be the response
### PHP
#### If you don't have Swoole already:
- `pecl install swoole`
#### Install dependencies
Mainly https://github.com/easy-swoole/kafka
- `composer install`
#### Start the consumer
- `php consumer.php`
## Let's play!
### Write some events
- `kafka/bin/kafka-console-producer.sh --topic my-topic --bootstrap-server localhost:9092`
Then just type some messages to the stdin. Press `Ctrl+C` to stop.

### A PHP producer
Just checkout [`producer.php`](producer.php).

## Let's Rock
### Easy


### Medium

### Hard

> âš Actually, I'm not sure if this is rocking. If you have a proper way to benchmark a consumer, please [issue me](https://github.com/leocavalcante/kafka-phplayground/issues).