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: 12
Type:project
Requires
- monolog/monolog: ^3.6
- nesbot/carbon: ^3.10
- promphp/prometheus_client_php: ^2.10
- vlucas/phpdotenv: ^5.6
Requires (Dev)
- dealerdirect/phpcodesniffer-composer-installer: ^1.1
- friendsofphp/php-cs-fixer: ^3.88
- pheromone/phpcs-security-audit: ^2.0
- phpcompatibility/php-compatibility: ^9.3
- 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: ^10.5
- rector/rector: ^2.1
- slevomat/coding-standard: ^8.20
- squizlabs/php_codesniffer: ^3.13
- swoole/ide-helper: ~5.0.0
- zircote/swagger-php: ^5.3
- dev-main
- v1.0.5
- v1.0.4
- v1.0.3
- v1.0.2
- v1.0.1
- v1.0.0
- dev-renovate/phpunit-phpunit-12.x
- dev-renovate/swoole-ide-helper-6.x
- dev-renovate/actions-checkout-5.x
- dev-renovate/swoole-ide-helper-5.x
- dev-renovate/phpstan-packages
- dev-renovate/phpunit-phpunit-10.x-lockfile
- dev-renovate/redis-8.x
- dev-renovate/caddy-2.x
- dev-renovate/mysql-9.x
- dev-renovate/squizlabs-php_codesniffer-4.x
This package is auto-updated.
Last update: 2025-10-03 18:49:14 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
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
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/crud_load_test_real.js > logs/k6_real.log 2>&1 k6 run --http-debug="full" k6/crud_load_test_read.js > logs/k6_read.log 2>&1 k6 run --http-debug="full" k6/crud_load_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 and MySQL exporter.
- Grafana visualizes metrics (default port:
3000
).
Environment Variables
All configurable options are defined in docker-compose.yml
and .env.example
.
License
MIT