jafaripur / php-microservice-application-yii2
php-microservice skeleton console application starter with Yii3 for microservice node
Installs: 10
Dependents: 0
Suggesters: 2
Security: 0
Stars: 0
Watchers: 2
Forks: 1
Open Issues: 0
Type:project
Requires
- php: ^8.1
- jafaripur/php-microservice: dev-master
- jafaripur/php-microservice-user-service: dev-master
- monolog/monolog: ^2.3
- samdark/yii2-psr-log-target: ^1.1
- sentry/sdk: ^3.1
- spiral/roadrunner: ^2.7
- vlucas/phpdotenv: ^5.4
- yidas/yii2-composer-bower-skip: ~2.0.13
- yiisoft/yii2: ~2.0.46
Requires (Dev)
- codeception/codeception: ^4.0
- codeception/module-asserts: ^1.0.0
- codeception/module-filesystem: ^2.0
- codeception/module-yii2: ^1.0.0
- codeception/specify: ~0.4.6
- codeception/verify: ~1.1.0
- friendsofphp/php-cs-fixer: ^3.5
- overtrue/phplint: ^4.0
This package is auto-updated.
Last update: 2024-12-18 15:54:04 UTC
README
Yii2
console application used to write our processors of methods to responsible to client calling.
This application a template for microservice application and implement four methods of jafaripur/php-microservice. Another library created for using this microservice methods jafaripur/php-microservice-user-service.
For consuming and receiving data:
php yii_dev user-service/listen
For sending tests messages, By using this client library (jafaripur/php-microservice-user-service
):
php yii_dev user-service/send-test
Create project
composer create-project "jafaripur/php-microservice-application-yii2 dev-master" micro3
Configuration
Three env
file exist:
.env => For production
.env_dev => For development
.env_test => For test with codeception
Three entrypoint:
yii => For production
yii_dev => For development
yii_test => For test with codeception
Production Build
This application can be run with roadrunner
service plugin in production with Dockerfile docker/Dockerfile.prod
, Production build with docker:
export DOCKER_BUILDKIT=1 && docker build -f "./docker/Dockerfile.prod" -t "micro3-prod:latest" .
After building, we can create a container or docker swarm service. The production docker image runs with RoadRunner
. In this example we use this configuration for RoadRunner, config exist in .rr.yaml
file.
version: "2.7" service: topics: command: "php yii user-service/listen first-consumer" process_num: 10 exec_timeout: 0 remain_after_exit: true restart_sec: 5 emits: command: "php yii user-service/listen second-consumer" process_num: 2 exec_timeout: 0 remain_after_exit: true restart_sec: 5 logs: mode: production encoding: console
With this RoadRunner service plugin we can run several consumer with several instance.
For creating docker container from builded image:
docker run -d --init \ --name micro3-container \ --restart unless-stopped \ micro3-prod:latest
And for swarm service:
docker service create --name "micro3-service" \
--replicas 2 \
--update-delay 10s \
micro3-prod:latest
Test
# Run test docker-compose up --build micro # Stop and remove created containers docker-compose down