PHP MicroServices Examples
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.
Requirements To Run Test
- Composer
- PHP7
- PHP Sockets Extensions Installed
E-Mail and Socket Programming
Overview
The mail microservice uses basic socket communication between a socket server and service. For explanation, please read: PHP Microservices — Send Emails Over Sockets
How To Run
- 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
Video Processing and RabbitMQ
Overview
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
How To Run
- 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
Restful Crud API
Overview
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
How To Run
- 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
Organizing Access To Microservices
Overview
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.
How To Run
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
Authentication, Authorization, Functional Programming and Unit Tests
Overview
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:
How To Run The Microservice
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
How To Run Tests
- 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.
Socket vs HTTP Performance
Overview
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
How To Run
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