https://github.com/rxcod9/php-swoole-crud-microservice
PHP Swoole CRUD Microservice [WORKING DEMO]
https://github.com/rxcod9/php-swoole-crud-microservice
crud microservice mysql php pool swoole
Last synced: 2 months ago
JSON representation
PHP Swoole CRUD Microservice [WORKING DEMO]
- Host: GitHub
- URL: https://github.com/rxcod9/php-swoole-crud-microservice
- Owner: rxcod9
- Created: 2025-08-23T18:25:17.000Z (7 months ago)
- Default Branch: main
- Last Pushed: 2026-01-12T12:27:22.000Z (3 months ago)
- Last Synced: 2026-01-12T15:19:15.865Z (3 months ago)
- Topics: crud, microservice, mysql, php, pool, swoole
- Language: PHP
- Homepage:
- Size: 2.3 MB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 12
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- Funding: .github/FUNDING.yml
Awesome Lists containing this project
README
# PHP Swoole CRUD Microservice
A high-performance **PHP CRUD microservice** built with **Swoole**, featuring **MySQL**, **Redis**, **Prometheus**, **Grafana**, **Caddy**, and **Swagger UI** integration. Designed for **scalable**, **observable**, and **containerized** deployments.
By ๐ผ [Ramakant Gangwar](https://github.com/rxcod9)
# โ๏ธ Swagger / OpenAPI

# โก๏ธ Performance

# โค๏ธ Health

# ๐ Grafana Dashboards



[](https://github.com/rxcod9/php-swoole-crud-microservice/releases)

[](https://packagist.org/packages/rxcod9/php-swoole-crud-microservice)
---
## ๐ Features
- โก๏ธ Fast HTTP server powered by **Swoole**
- ๐๏ธ MySQL database with **connection pooling**
- ๐ Redis caching and pooling
- ๐ Prometheus metrics endpoint
- ๐ Grafana dashboards for monitoring
- ๐ **Caddy** for HTTPS and reverse proxy
- ๐ Swagger UI for API documentation
- โค๏ธ Health checks for all services
---
## ๐ Getting Started
### ๐งฐ Prerequisites
**Docker** & **Docker Compose**
### ๐ณ Docker Hub Quick Start
If you prefer using the pre-built Docker image, follow these steps:
```bash
# 1๏ธโฃ Prepare environment file
# Copy the example .env file (you can modify it to match your setup)
cp .env.example .env
```
```bash
# Example .env values
APP_ENV=production
APP_DEBUG=false
DB_HOST=mysql
DB_PORT=3306
DB_USER=root
DB_PASS=secret
DB_NAME=app_db
REDIS_HOST=redis
REDIS_PORT=6379
PROMETHEUS_PORT=9502
SWOOLE_HTTP_PORT=9501
```
Now run the container:
```bash
# ๐ Pull the latest image
docker pull rxcod9/php-swoole-crud-microservice:v1.0.24
# ๐ Run the container with .env file
docker run --env-file .env -d -p 9501:9501 --name php-crud-microservice rxcod9/php-swoole-crud-microservice
# ๐งฉ Run database migrations inside the running container
docker exec -it php-crud-microservice php scripts/migrate.php
```
### ๐งฉ Docker Compose Usage
This repository includes a `docker-compose.yml` to run the full stack:
```bash
# โถ๏ธ Start all services (PHP app, MySQL, Redis, Prometheus, Grafana, Caddy)
docker compose up -d --build
# โน๏ธ Stop all services
docker compose down
# ๐ View logs
docker compose logs -f
```
Edit `.env` or `docker-compose.override.yml` to customize ports and database credentials.
### โก๏ธ Quick Start
```bash
# ๐ Copy example environment
cp .env.example .env
# ๐ฆ Install PHP dependencies
composer install
# ๐ Start all services in detached mode
docker compose up -d --build
```
### ๐๏ธ Database Migration
```bash
# ๐งญ Run migrations inside the app container
docker compose exec app php scripts/migrate.php
```
### ๐ API Documentation
```bash
# ๐งฉ Generate OpenAPI spec
php bin/generate-swagger.php
```
Access Swagger UI at [http://localhost:8080](http://localhost:8080)
---
## ๐ง Example API Usage
```bash
# โ Create a user
curl -s -X POST http://localhost:9501/users -H 'Content-Type: application/json' -d '{"name":"alice","email":"alice@example.com"}'
# ๐ Get all users
curl -s -X GET http://localhost:9501/users -H 'Content-Type: application/json' | jq
# ๐ Get a user by ID
curl -s -X GET http://localhost:9501/users/1 -H 'Content-Type: application/json' | jq
# ๐ Get a user by email
curl -s -X GET http://localhost:9501/users/email/alice%40example.com -H 'Content-Type: application/json' | jq
# โ๏ธ Update a user
curl -i -X PUT http://localhost:9501/users/1 -H 'Content-Type: application/json' -d '{"name":"alice-updated","email":"alice-updated@example.com"}'
# โ Delete a user
curl -i -X DELETE http://localhost:9501/users/1 -H 'Content-Type: application/json'
```
---
## โ๏ธ Benchmarking
```bash
# ๐งช Using k6
k6 run --http-debug="full" k6 run k6/tests/crud_load_test.js > logs/k6.log 2>&1
# k6 command with all possible ENV variables
k6 run \
-e BASE_URL=http://localhost:9501 \
-e ENTITIES=users,items \
-e CRUD=list,read,create,update \
-e TOTAL_ENTITIES=200 \
-e HOT_PERCENT=0.3 \
-e COOL_PERCENT=0.3 \
-e TOTAL_EXECUTIONS=2000 \
-e MAX_VUS=50 \
-e MAX_DURATION=10m \
--http-debug="full" \
tests/crud_main_test.js > logs/k6.log 2>&1
# ๐งฉ Using ApacheBench
ab -n 100000 -c 100 -v 4 http://localhost:9501/users/1 2>&1 | tee ab.log
```
---
## ๐ก Monitoring
- ๐ **Prometheus** scrapes metrics from the app, MySQL exporter and Redis Exporter.
- ๐ **Grafana** visualizes metrics (default port: `3000`).
---
## โ๏ธ Environment Variables
All configurable options are defined in `docker-compose.yml` and `.env.example`.
---
## ๐งพ License
MIT