Download the PHP package piwvh/php-eureka without Composer
On this page you can find all versions of the php package piwvh/php-eureka. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
All versions of php-eureka with dependencies
Informations about the package php-eureka
PHP Netflix Eureka Client
A PHP client for (Spring Cloud) Netflix Eureka service registration and discovery.
You can install this package using Composer:
composer require "piwvh/php-eureka"
Create Eureka Client
The very first thing you need to do is to create an instance of
EurekaClient using your own configuration:
List of all available configuration are as follows:
You can also change the configuration after creating
EurekaClient instance, using setter methods:
After creating EurekaClient instance, there will be multiple operations to perform:
Registration: register your service instance with Eureka
De-registration: de-register your service instance from Eureka
- Heartbeat: send heartbeat to Eureka, to show the client is up (one-time heartbeat)
You can register your instance and send periodic heartbeat using
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
heartbeatInterval configuration value. This interval time can be changed just like any other
It's apparent that this method should be used in CLI.
- Service Discovery: fetch an instance of a service from Eureka:
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
Then, all you have to do is to introduce your custom strategy to
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
getInstances() method of this interface and returning instances
of a service based on your ideal logic.
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:
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
which fetches all of the instances of the service from Eureka: