islamic-network/microservice-helpers

There is no license information available for the latest version (1.0) of this package.

PHP Package to make microservices consistent

1.0 2019-09-27 12:14 UTC

This package is auto-updated.

Last update: 2024-02-29 03:38:17 UTC


README

CircleCI Latest Stable Version Total Downloads License Monthly Downloads Daily Downloads composer.lock

This is a group of various PHP helpers that have been extrapolated from the AlAdhan and AlQuran APIs.

They can be used on any projects that use PHP 7.1+.

Current Packages

  1. A Response helper, which standardizes JSON responses for APIs by including the HTTP code and status in the response itself. See https://api.aladhan.com/v1/gToH, for example.
  2. Health check monitors for:
  • Memcached
  • Redis
  • MySQL

Installation

composer require islamic-network/microservice-helpers

How to Use to Build a Healthcheck page, for instance

use IslamicNetwork\MicroServiceHelpers\Monitors\Memcached;
use IslamicNetwork\MicroServiceHelpers\Monitors\Redis;
use use IslamicNetwork\MicroServiceHelpers\Monitors\MySql;
use IslamicNetwork\MicroServiceHelpers\Formatters\Response;

// Create monitors
$memcachedMonitor = new Memcached($host, $port);
$redisMonitor = new Redis($host, $port);
$mysqlMonitor = new MySql($host, $port);

if (!$memcachedMonitor || !$redisMonitor || !$mysqlMonitor) {
    $httpCode = 500;
} else {
    $httpCode = 200;
}

Response::build(
    [ 
        'memcached' => $memcachedMonitor->status(),
        'redis' => $redisMonitor->status(),
        'mysql' => $mysqlMonitor->status(),
    ],
    $httpCode
);