Home Page Icon
Home Page
Table of Contents for
PHP Microservices
Close
PHP Microservices
by Pablo Solar Vilariño, Carlos Pérez Sánchez
PHP Microservices
PHP Microservices
PHP Microservices
Credits
About the Authors
About the Reviewer
www.PacktPub.com
Why subscribe?
Customer Feedback
Preface
What this book covers
What you need for this book
Who this book is for
Conventions
Reader feedback
Customer support
Downloading the example code
Errata
Piracy
Questions
1. What are Microservices?
Monolithic versus microservices
Service Oriented Architectures versus microservices
Microservices characteristics
Successful cases
Disadvantages of microservices
How to focus your development on microservices
Always create small logical black boxes
Network latency is your hidden enemy
Always think about scalability
Use a lightweight communication protocol
Use queues to reduce a service load or make async executions
Be ready for the worst case scenario
Each service is different, so keep different repositories and build environments
Advantages of using PHP on microservices
A short history of PHP
PHP milestones
Version 4.x
Version 5.x
Version 6.x
Version 7.x
Advantages
Disadvantages
Summary
2. Development Environment
Design and architecture to build the basic platform for microservices
Requirements to start working on microservices
Docker installation
Installing Docker on macOS
Docker for Mac (alias, native implementation) versus Docker toolbox
Minimum requirements
Docker for Mac installation process
Installing Docker on Linux
CentOS/RHEL
Minimum requirements
Installing Docker using yum
Post-install setup - creating a Docker group
Installing Docker on Ubuntu
Minimum requirements
Installing Docker using apt
Common issues on Ubuntu
UFW forwarding
DNS server
Post-install setup – creating a Docker group
Starting Docker on boot
Installing Docker on Windows
Minimum requirements
Installing the Docker tools
How to check your Docker engine, compose, and machine versions
Quick example to check your Docker installation
Common management tasks
Version control – Git versus SVN
Git
Hosting
GitHub
BitBucket
Version control strategies
Centralized work
Feature branch workflow
Gitflow workflow
Forking workflow
Semantic versioning
Setting up a development environment for microservices
Autodiscovery service
Microservice base core - NGINX and PHP-FPM
Frameworks for microservices
PHP-FIG
PSR-7
Messages
Headers
Host header
Streams
Request targets and URIs
Server-side requests
Uploaded files
Middleware
Available frameworks
Phalcon
Slim framework
Lumen
Zend Expressive
Silex (based on Symfony)
Summary
3. Application Design
Microservices structure
Microservice patterns
API gateway
Service discovery and registry
Shared database or database per service
Database per service
Shared database
RESTful conventions
Security
Standards
Consumer amenities
Caching strategy
General caching strategy
HTTP caching
Static files caching
Domain-driven design
How domain-driven design works
Using domain-driver design in microservices
Event-driven architecture
Event-driven architecture in microservices
Continuous integration, continuous delivery, and tools
Continuous integration - CI
What is continous integration?
Benefits of CI
Tools for continuous integration
Continuous delivery
Benefits of continuous delivery
Tools for a continuous delivery pipeline
Summary
4. Testing and Quality Control
The importance of using tests in your application
Testing in microservices
Test-driven development
How to do TDD?
Why should I use TDD?
TDD algorithm
Red - writing the unit tests
Green - make the code work
Refactor - eliminate redundancy
Behavior-driven development
What is BDD?
How does it work?
Cucumber as DSL for BDD
Acceptance test-driven development
User stories
ATDD algorithm
Discuss
Distill
Develop
Demo
Tools
Composer
PHPUnit
Unit testing
Running the tests
Assertions
assertArrayHasKey
assertClassHasAttribute
assertArraySubset
assertClassHasStaticAttribute
assertContains()
assertDirectory() and assertFile()
assertString()
assertRegExp()
assertJson()
Boolean assertions
Type assertions
Other assertions
Unit testing from scratch
Behat
Installation
Test execution
Behat example from scratch
Selenium
Selenium WebDriver
Selenium IDE
Summary
5. Microservices Development
Dependency management
Routing
Postman
Middleware
Implementing a microservice call
Request life cycle
Communication between microservices with Guzzle
Database operations
Error handling
Validation
Manage exceptions
Async and queue
Caching
Summary
6. Monitoring
Debugging and profiling
What is debugging?
What is profiling?
Debugging and profiling in PHP with Xdebug
Debugging installation
Debugging setup
Debugging the output
Profiling installation
Profiling setup
Analyzing the output file
Error handling
What is error handling?
Why is error handling important?
Challenges when managing error handling with microservices
Basic die() function
Custom error handling
Report method
Render method
Error handling with Sentry
Application logs
Challenges in microservices
Logs in Lumen
Application monitoring
Monitoring by levels
Application level
Datadog
Infrastructure level
Prometheus
Weave Scope
Hardware/hypervisor monitoring
Summary
7. Security
Encryption in microservices
Database encryption
Encryption in MariaDB
InnoDB encryption
Performance overhead
TSL/SSL protocols
How the TSL/SSL protocol works
TSL/SSL termination
TSL/SSL with NGINX
Authentication
OAuth 2
How to use OAuth 2 on Lumen
OAuth 2 installation
Setup
Let's try OAuth2
JSON Web Token
How to use JWT on Lumen
Setting up JWT
Let's try JWT
Access Control List
What is ACL?
How to use ACL
Security of the source code
Environment variables
External services
Tracking and monitoring
Best practices
File permissions and ownership
PHP execution locations
Never trust users
SQL injection
Cross-site scripting XSS
Session hijacking
Remote files
Password storage
Password policies
Source code revelation
Directory traversal
Summary
8. Deployment
Dependency management
Composer require-dev
The .gitignore file
Vendor folder
Deployment workflows
Vendor folder on repository
Composer in production
Frontend dependencies
Grunt
Gulp
SASS
Bower
Deploy automation
Simple PHP script
Ansible and Ansistrano
Ansible requirements
Ansible installation
What is Ansistrano?
How does Ansistrano work?
Deploying with Ansistrano
Other deployment tools
Advanced deployment techniques
Continuous integration with Jenkins
Blue/Green deployment
Canary releases
Immutable infrastructure
Backup strategies
What is backup?
Why is it important?
What and where we need to back up
Backup types
Full backup
Incremental and differential backups
Backup tools
Bacula
Percona xtrabackup
Custom scripts
Validating backups
Be ready for the apocalypse
Summary
9. From Monolithic to Microservices
Refactor strategies
Stop diving
Divide frontend and backend
Extraction services
How to extract a module
Tutorial: From monolithic to microservices
Stop diving
Divide frontend and backend
Extraction services
Summary
10. Strategies for Scalability
Capacity planning
Knowing the limits of your application
Availability math
Load testing
Apache JMeter
Installing Apache JMeter
Executing load tests with Apache JMeter
Load testing with Artillery
Installing Artillery
Executing loading tests with Artillery
Creating Artillery scripts
Advanced scripting
Load testing with siege
Installing siege on RHEL, CentOS, and similar operating systems
Installing siege on Debian or Ubuntu
Installing siege on other OS
Quick siege example
Scalability plan
Step #0
Step #1
Step #2
Step #3
Step #4
Step #5
Summary
11. Best Practices and Conventions
Code versioning best practices
Caching best practices
Performance impact
Handle cache misses
Group requests
Size of elements to be stored in cache
Monitor your cache
Choose your cache algorithm carefully
Performance best practices
Minimize HTTP requests
Minimize HTML, CSS, and JavaScript
Image optimization
Use sprites
Use lossless image compression
Scale your images
Use data URIs
Cache, cache, and more cache
Avoid bad requests
Use Content Delivery Networks (CDNs)
Dependency management
Semantic versioning
How semantic versioning works
Semantic versioning in action
We have been told to add a new feature to the project
We have been told that there is a bug in our project
We have been asked for a big change
Error handling
Client request successful
Request redirected
Client request incomplete
Server errors
Coding practices
Dealing with strings
Single quotes versus double quotes
Spaces versus tabs
Regular expressions
Connection and queries to a database
Using the === operator
Working with release branches
Quick example
Summary
12. Cloud and DevOps
What is Cloud?
Autoscalable and elastic
Lower management efforts
Cheaper
Grow faster
Time to market
Select your Cloud provider
Amazon Web Services (AWS)
Microsoft Azure
Rackspace
DigitalOcean
Joyent
Google Compute Engine
Deploying your application to the Cloud
Docker Swarm
Installing Docker Swarm
Adding services to our Swarm
Scaling your services in Swarm
Apache Mesos and DC/OS
Kubernetes
Deploying to Joyent Triton
What is DevOps?
Summary
Search in book...
Toggle Font Controls
Playlists
Add To
Create new playlist
Name your new playlist
Playlist description (optional)
Cancel
Create playlist
Sign In
Email address
Password
Forgot Password?
Create account
Login
or
Continue with Facebook
Continue with Google
Sign Up
Full Name
Email address
Confirm Email Address
Password
Login
Create account
or
Continue with Facebook
Continue with Google
Prev
Previous Chapter
Table of Contents
Next
Next Chapter
PHP Microservices
PHP Microservices
Add Highlight
No Comment
..................Content has been hidden....................
You can't read the all page of ebook, please click
here
login for view all page.
Day Mode
Cloud Mode
Night Mode
Reset