This is a repo of example MicroServices using PHP. Areas of topics will include:
- Socket Programming
- RabbitMQ Example
- RESTFUL Example
- Authentication and Authorization Example
- Functional Programming Example
Many of the examples use ProdigyView Toolkit for development.
- Composer
- PHP7
- PHP Sockets Extensions Installed
The mail microservice uses basic socket communication between a socket server and service. For explanation, please read: PHP Microservices — Send Emails Over Sockets
- Go to the
email
folder - Run
composer install
to install required packages - Open up two tabs in your console
- In one tab, run
php server.php
- In the other tab, run
php client.php
The services shows a basic example of how to create a service for processing videos with RabbitMQ. For detailed explanation of the service, please visit: PHP Microservices — Video Processing With RabbitMQ
- Ensure RabbitMQ is installed and running locally
- Go to the
video
folder - Run
composer install
to install required packages - Open up two tabs in your console
- In one tab, run
php server.php
- In the other tab, run
php client.php
This tutorial will demonstrate how to create a basic REST api for processing CRUD operation at an endpoint. For detailed information, please visit: PHP Microservices — Creating A Basic Restful Crud API
- Go to the
rest
folder - Run
composer install
to install required packages - Open up two tabs in your console
- In one tab, we need to start a php server with
php -S 127.0.0.1:8080
- In the other tab, run
php client.php
This section will show how to organize and manage multiple microservices. The past 3 examples have been combined into one, with the addition of sending pushing notifications and image processing. The goal is to give each service their own resources, and organize calling them via REST API.
For detailed work through please read Organizing Access To Multiple Services.
We will need four tabs to effectively run this example.
- Start your RabbitMQ Server
- Go the the
multiple
folder - Run
composer install
to install required packages - Have your four tabs open to this folder
- Start the webserver with
php -S 127.0.0.1:8090
in one tab - Start the notification server with
php servers/notification_server.php
in the 2nd tab - Start the media server with
php servers/media_server.php
in the 3rd tab - Execute the tests by running
php client.php
in the last tab
This part of the tutorials covers how to perform Authentication and Authorization between microservices. It also includes an additional information on how to do function programming and unit test. Accompanying tutorial are as followings:
Running this example requires 4 tabs on your console.
- Go to the
security
folder. - Run
composer install
to install required packages - Make sure your 4 tabs are open in this directory
- Start the web server with
php -S 127.0.0.1:8000
- Start the authentications server with
php authentication_service/server.php
- Start the purchase server with
php payment_server/server.php
- Run the client with
php client.php
in the final tab
- Go to the
security
folder. - Run
composer install
to install required packages - Type
./vendor/bin/phpunit --bootstrap vendor/autoload.php tests/AuthenticationServerTest.php
for Authentication Tests.
This tutorial and test will bring you through comparing the performance of a RESTFUL API vs Sockets. You may read along about the tests here: REST vs Socket Performance Benchmarks
This test will require that 3 tabs open.
- Go to the
socket_vs_http
folder. - Run
composer install
to install required packages - Have your 3 tabs open
- In your first tab, start the web server with
php -S 127.0.0.1:8000 -t http_server/
- In the second tab, start the socket with
php socket_server/server.php
- In the final tab, run the client with
php client.php