PHP Microservices — Send Emails Over Sockets

Devin Dixon
Helium MVC

--

This article is part of a series that discusses how to start breaking your application into microservices to improve maintainability and scalability.

A microservice is a piece of your application that exists as a standalone service with its own resources(database, server, infrastructure, etc). The purpose of microservices to break apart our application into smaller pieces. The result is our application is easier to manage, more scalable and we can optimize performance.

As an example of how to create a microservice, in this tutorial we will create a microservice for sending emails. We chose emails because it is an easy starting point that can improve your system. Sending emails can become expensive with your server resources. The steps that involve sending an email include:

  1. Gathering the information (name, email, message, etc)
  2. Generating a template to put the information in
  3. Potential attaching files, calendar invites, etc
  4. Connecting with an email service (blocking I/O)
  5. Receiving a response from the email service ( more blocking I/O)
  6. Logging that response (and more blocking I/O)

The majority of these steps can be done off the web server and in a microservice to better…

--

--