rxcod9 / php-swoole-crud-microservice
PHP Swoole CRUD Microservice
Fund package maintenance!
Patreon
Installs: 0
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 9
Type:project
pkg:composer/rxcod9/php-swoole-crud-microservice
Requires
- monolog/monolog: ^3.6
- nesbot/carbon: ^3.10
- promphp/prometheus_client_php: ^2.10
- vlucas/phpdotenv: ^5.6
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.88
- phpdocumentor/reflection-docblock: ^5.6
- phpmd/phpmd: ^2.15
- phpstan/phpdoc-parser: ^2.3
- phpstan/phpstan: ^2.1
- phpstan/phpstan-strict-rules: ^2.0
- phpunit/phpunit: ^12.4
- rector/rector: ^2.2
- squizlabs/php_codesniffer: ^4.0
- swoole/ide-helper: ^6.0
- zircote/swagger-php: ^5.4
- dev-main
- v1.0.28
- v1.0.27
- v1.0.26
- v1.0.25
- v1.0.24
- v1.0.23
- v1.0.22
- v1.0.21
- v1.0.20
- v1.0.19
- v1.0.18
- v1.0.17
- v1.0.16
- v1.0.15
- v1.0.14
- v1.0.13
- v1.0.12
- v1.0.11
- v1.0.10
- v1.0.9
- v1.0.8
- v1.0.7
- v1.0.6
- v1.0.5
- v1.0.4
- v1.0.3
- v1.0.2
- v1.0.1
- v1.0.0
- dev-renovate/rector-rector-2.x-lockfile
- dev-renovate/phpstan-packages
- dev-renovate/phpunit-phpunit-12.x-lockfile
- dev-renovate/nesbot-carbon-3.x-lockfile
- dev-renovate/zircote-swagger-php-5.x-lockfile
- dev-renovate/quay.io-prometheus-busybox-linux-amd64
- dev-renovate/prom-prometheus-3.x
- dev-renovate/friendsofphp-php-cs-fixer-3.x-lockfile
- dev-renovate/phpdocumentor-reflection-docblock-5.x-lockfile
- dev-feature/php8.5
- dev-feature/async-crud
This package is auto-updated.
Last update: 2025-12-05 12:45:59 UTC
README
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
โ๏ธ Swagger / OpenAPI
โก๏ธ Performance
โค๏ธ Health
๐ Grafana Dashboards
๐ 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:
# 1๏ธโฃ Prepare environment file # Copy the example .env file (you can modify it to match your setup) cp .env.example .env
# 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:
# ๐ 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:
# โถ๏ธ 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
# ๐ 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
# ๐งญ Run migrations inside the app container docker compose exec app php scripts/migrate.php
๐ API Documentation
# ๐งฉ Generate OpenAPI spec
php bin/generate-swagger.php
Access Swagger UI at http://localhost:8080
๐ง Example API Usage
# โ 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
# ๐งช 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





