A PHP client for (Spring Cloud) Netflix Eureka service registration and discovery.

Overview

PHP Netflix Eureka Client

A PHP client for (Spring Cloud) Netflix Eureka service registration and discovery.

Installation

You can install this package using Composer:

composer require "piwvh/php-eureka"

Documentation

Create Eureka Client

The very first thing you need to do is to create an instance of EurekaClient using your own configuration:

$client = new EurekaClient([
    'eurekaDefaultUrl' => 'http://localhost:8761/eureka',
    'hostName' => 'service.hamid.work',
    'appName' => 'service',
    'ip' => '127.0.0.1',
    'port' => ['8080', true],
    'homePageUrl' => 'http://localhost:8080',
    'statusPageUrl' => 'http://localhost:8080/info',
    'healthCheckUrl' => 'http://localhost:8080/health'
]);

List of all available configuration are as follows:

  • eurekaDefaultUrl (default: http://localhost:8761);
  • hostName
  • appName
  • ip
  • status (default: UP)
  • overriddenStatus (default: UNKNOWN)
  • port
  • securePort (default: ['443', false])
  • countryId (default: 1)
  • dataCenterInfo (default: ['com.netflix.appinfo.InstanceInfo$DefaultDataCenterInfo', 'MyOwn'])
  • homePageUrl
  • statusPageUrl
  • healthCheckUrl
  • vipAddress
  • secureVipAddress
  • heartbeatInterval (default: 30)
  • discoveryStrategy (default: RandomStrategy)
  • instanceProvider

You can also change the configuration after creating EurekaClient instance, using setter methods:

$client->getConfig()->setAppName("my-service");

Operations

After creating EurekaClient instance, there will be multiple operations to perform:

  • Registration: register your service instance with Eureka
$client->register();
  • De-registration: de-register your service instance from Eureka
$client->deRegister();
  • Heartbeat: send heartbeat to Eureka, to show the client is up (one-time heartbeat)
$client->heartbeat();

You can register your instance and send periodic heartbeat using start() method:

$client->start();

Using this method, first your service gets registered with Eureka using the configuration you have provided. Then, a heartbeat will be sent to the Eureka periodically, based on heartbeatInterval configuration value. This interval time can be changed just like any other configuration item:

$client->getConfig()->setHeartbeatInterval(60); // 60 seconds

It's apparent that this method should be used in CLI.

  • Service Discovery: fetch an instance of a service from Eureka:
homePageUrl; ">
$instance = $client->fetchInstance("the-service");
$homePageUrl = $instance->homePageUrl;

Discovery Strategy

When fetching instances of a service from Eureka, you probably get a list of available instances. You can choose one of them based on your desired strategy of load balancing. For example, a Round-robin or a Random strategy might be your choice.

Currently, this library only supports RandomStrategy, however, you can create your custom strategy by implementing getInstance() method of DiscoveryStrategy interface:

class RoundRobinStrategy implements DiscoveryStrategy {

    public function getInstance($instances) {
        // return an instance
    }
    
}

Then, all you have to do is to introduce your custom strategy to EurekaClient instance:

$client->getConfig()->setDiscoveryStrategy(new RoundRobinStrategy());

Local Registry and Caching

Failure is inevitable, specially in cloud-native applications. Thus, sometimes Eureka may not be available because of failure. In these cases, we should have a local registry of services to avoid cascading failures.

By default, if Eureka is down, the fetchInstance() method fails, so an exception would be thrown and the application cannot continue to work. To solve this problem, you should create a local registry of services.

There is an interface called InstanceProvider which you can make use of, by implementing getInstances() method of this interface and returning instances of a service based on your ideal logic.

class MyProvider implements InstanceProvider {

    public function getInstances($appName) { 
        // return cached instances of the service from the Redis 
    }
}

In this example, we have cached the instances of the service in the Redis and are loading them when Eureka is down.

After creating your custom provider, just make it work by adding it to the configuration:

$client->getConfig()->setInstanceProvider(new MyProvider());

Your custom provider only gets called when Eureka is down or is not answering properly.

That's all you need to do. By adding this functionality, your application keeps working even when Eureka is down.

For caching all available instances of a specific service, you can call fetchInstances() method which fetches all of the instances of the service from Eureka:

$instances = $client->fetchInstances("the-service");
You might also like...
Yet another PHP Microframework.

ρ Yet another PHP Microframework. The premise of this framework is to be backwards-compatible (PHP = 5.6) with powerful utilities (Like caching and l

Frankie - A frankenstein micro-framework for PHP

Frankie - A frankenstein micro-framework for PHP Features Frankie is a micro-framework focused on annotation. The goal is to use annotation in order t

ExEngine is an ultra lightweight micro-services framework for PHP 5.6+

ExEngine is an ultra lightweight micro-services framework for PHP 5.6+. Documentation Checkout the Wiki. Examples Click here to browse examples, also

REST-like PHP micro-framework.

Phprest Description REST-like PHP micro-framework. It's based on the Proton (StackPhp compatible) micro-framework. Phprest gives you only the very bas

This is a Location Registration For location registration

location-registration-system This is a Location Registration location-registration-system for users registration location if your location verifide Wi

This application is a simple application to watch movies like Netflix or DisneyPlus.

Movie Streaming React Web Apps This application is a simple application to watch streaming movies like Netflix or DisneyPlus. The application is built

This library extends the 'League OAuth2 Client' library to provide OpenID Connect Discovery support for supporting providers that expose a .well-known configuration endpoint.

OpenID Connect Discovery support for League - OAuth 2.0 Client This library extends the League OAuth2 Client library to provide OpenID Connect Discove

Dictionary of attack patterns and primitives for black-box application fault injection and resource discovery.

FuzzDB was created to increase the likelihood of finding application security vulnerabilities through dynamic application security testing. It's the f

CollectiveAccess is a web-based suite of applications providing a framework for management, description, and discovery of complex digital

README: Pawtucket2 version 1.7.14 About CollectiveAccess CollectiveAccess is a web-based suite of applications providing a framework for management, d

Auto Route Generating (Auto-Discovery) Package for Laravel.

Laravel Auto Routes _ _____ _ /\ | | | __ \ | |

Middleware to use FastRoute for handler discovery

middlewares/fast-route Middleware to use FastRoute for handler discovery. Requirements PHP = 7.2 A PSR-7 http library A PSR-15 middleware dispatcher

Cipi is a Laravel based cloud server control panel that supports Digital Ocean, AWS, Vultr, Google Cloud, Linode, Azure and other VPS.
Cipi is a Laravel based cloud server control panel that supports Digital Ocean, AWS, Vultr, Google Cloud, Linode, Azure and other VPS.

Cipi is a Laravel based cloud server control panel that supports Digital Ocean, AWS, Vultr, Google Cloud, Linode, Azure and other VPS. It comes with nginx, Mysql, multi PHP-FPM versions, multi users, Supervisor, Composer, npm, free Let's Encrypt certificates, Git deployment, backups, ffmpeg, fail2ban, Redis, API and with a simple graphical interface useful to manage Laravel, Codeigniter, Symfony, WordPress or other PHP applications. With Cipi you don’t need to be a Sys Admin to deploy and manage websites and PHP applications powered by cloud VPS.

 amadeus-ws-client: PHP client for the Amadeus GDS SOAP Web Service interface
amadeus-ws-client: PHP client for the Amadeus GDS SOAP Web Service interface

amadeus-ws-client: PHP client for the Amadeus GDS SOAP Web Service interface This client library provides access to the Amadeus GDS SOAP Web Service i

Provides a clean and simple way to configure the WordPress-bundled PHPMailer library, allowing you to quickly get started sending mail through a local or cloud based service of your choice

WP PHPMailer provides a clean and simple way to configure the WordPress-bundled PHPMailer library, allowing you to quickly get started sending mail through a local or cloud based service of your choice.

This package makes it easy for developers to access WhatsApp Cloud API service in their PHP code.
This package makes it easy for developers to access WhatsApp Cloud API service in their PHP code.

The first PHP API to send and receive messages using a cloud-hosted version of the WhatsApp Business Platform

Google Cloud Database Migration Service for PHP

Google Cloud Database Migration Service for PHP Idiomatic PHP client for Google Cloud Database Migration Service. API documentation NOTE: This reposit

High-quality cloud service for text translation. 100+ Languages
High-quality cloud service for text translation. 100+ Languages

CloudAPI.Stream High-quality cloud service for text translation. 100+ Languages https://cloudapi.stream/ Class initialization $CAS = new CAS; Key inst

User registration and login form with validations and escapes for total security made with PHP.

Login and Sign Up with PHP User registration and login form with validations and escapes for total security made with PHP. Validations Required fields

Comments
  • How to make always send heartbeat with run application?

    How to make always send heartbeat with run application?

    Hello,

    Im trying to send heartbeat like this

    try { $client->register(); $url = $client->fetchInstance("test")->homePageUrl; var_dump($url); $client->start(); }

    Yes its working but the application not running. Any guide how to send heartbeat with running application?

    Best Regards, Alfa

    opened by AlfaIrawan 4
Releases(0.0.2)
Owner
Hamid Mohayeji
I'm a software engineer interested in software engineering & architecture, alongside machine learning.
Hamid Mohayeji
⚡ Flat-files and plain-old PHP functions rockin'on as a set of general purpose high-level abstractions.

Siler is a set of general purpose high-level abstractions aiming an API for declarative programming in PHP. ?? Files and functions as first-class citi

Leo Cavalcante 1.1k Dec 30, 2022
StackSync is a simple, lightweight and native fullstack PHP mini-framework.

StackSync is a fullstack PHP mini framework, with an MVC structure, custom API system with a Middleware and JWT authentication, components based views, flexible routing, PSR4 autoloading. Essential files generation (migrations, seeders, controllers and models) and other operations can be executed through custom commands.

Khomsi Adam 3 Jul 24, 2022
🐺 Lightweight and easy to use framework for building web apps.

Wolff Web development made just right. Wolff is a ridiculously small and lightweight PHP framework, intended for those who want to build web applicati

Alejandro 216 Dec 8, 2022
Blink is a micro web framework for building long-running and high performance services

Blink is a micro web framework for building long-running and high performance services, the design heavily inspired by Yii2 and Laravel. Blink aims to provide the most expressive and elegant API and try to make the experience of web development as pleasant as possible.

Jin Hu 837 Dec 18, 2022
Larasymf - mini framework for medium sized projects based on laravel and symfony packages

Larasymf, PHP Framework Larasymf, as its says is a mini framework for medium sized projects based on laravel and symfony packages We have not yet writ

Claude Fassinou 6 Jul 3, 2022
[DEPRECATED -- Use Symfony instead] The PHP micro-framework based on the Symfony Components

Silex, a simple Web Framework WARNING: Silex is in maintenance mode only. Ends of life is set to June 2018. Read more on Symfony's blog. Silex is a PH

Silex 3.6k Dec 22, 2022
A resource-oriented micro PHP framework

Bullet Bullet is a resource-oriented micro PHP framework built around HTTP URIs. Bullet takes a unique functional-style approach to URL routing by par

Vance Lucas 415 Dec 27, 2022
VELOX - The fastest way to build simple websites using PHP!

VELOX The fastest way to build simple websites using PHP! Table of Contents Installation About VELOX Architecture Config Classes Functions Themes Chan

Marwan Al-Soltany 53 Sep 13, 2022
Lemon is php micro framework built for simple applications.

Lemon is simple micro framework that provides routing, etc.

Lemon 20 Dec 16, 2022
TidyPHP is a micro php framework to build web applications

TidyPHP is a micro MVC PHP Framework made to understand how PHP Frameworks work behind the scense and build fast and tidy php web applications.

Amin 15 Jul 28, 2022