PHPackages                             roshandelpoor/register-php-app-in-eureka - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [HTTP &amp; Networking](/categories/http)
4. /
5. roshandelpoor/register-php-app-in-eureka

ActiveLibrary[HTTP &amp; Networking](/categories/http)

roshandelpoor/register-php-app-in-eureka
========================================

This Package is Eureka Client And it's a library that interacts with the Eureka Server to register, deregister, and discover other services. Finally, I Want To Emphasize that This is NOT New Package (ONLY Fix Bug for package piwvh/php-eureka) Because of My Microservices Projects that I have to custom it

132PHP

Since Oct 12Pushed 2y ago1 watchersCompare

[ Source](https://github.com/roshandelpoor/register-php-app-in-eureka)[ Packagist](https://packagist.org/packages/roshandelpoor/register-php-app-in-eureka)[ RSS](/packages/roshandelpoor-register-php-app-in-eureka/feed)WikiDiscussions main Synced 3w ago

READMEChangelog (2)DependenciesVersions (2)Used By (0)

Register PHP App In Eureka (Netflix Eureka Spring Cloud)
========================================================

[](#register-php-app-in-eureka-netflix-eureka-spring-cloud)

This Package is Eureka Client And it's a library that interacts with the Eureka Server to register, deregister, and discover other services. ( Spring Boot - Eureka Server is an application that holds the information about all client-service applications. Every Micro service will register into the Eureka server and Eureka server knows all the client applications running on each port and IP address. Eureka Server is also known as Discovery Server.)

Finally, I Want To Emphasize that This is NOT New Package (ONLY Fix Bug for package piwvh/php-eureka) Because of My Microservices Projects that I have to custom it.

Installation
============

[](#installation)

You can install this package using \[Composer\]:

`composer require --dev roshandelpoor/register-php-app-in-eureka:dev-main`

Documentation
=============

[](#documentation)

### Create Eureka Client

[](#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/myeureka',
    'hostName'          => gethostname(),
    'appName'           => 'NAME_APP_FOR_REGISTER_IN_EUREKA',
    'ip'                => '127.0.0.1',
    'port'              => ['8000', true],
    'homePageUrl'       => 'http://localhost:8000',
    'statusPageUrl'     => 'http://localhost:8000/info',
    'healthCheckUrl'    => 'http://localhost:8000/health'
]);
```

List of all(default) available configuration are as follows:

- `eurekaDefaultUrl` (default: `http://localhost:8761/myeureka`);
- `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->getEurekaConfig()->setAppName("NAME_APP_FOR_REGISTER_IN_EUREKA");
```

### Operations

[](#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->getEurekaConfig()->setHeartbeatInterval(30); // 30 seconds
```

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

- **Service Discovery**: fetch an instance of a service from Eureka:

```
$instance = $client->fetchInstance("the-service");
$homePageUrl = $instance->homePageUrl;
```

### Discovery Strategy

[](#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->getEurekaConfig()->setDiscoveryStrategy(new RoundRobinStrategy());
```

### Local Registry and Caching

[](#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->getEurekaConfig()->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 the instances of the service from Eureka:

```
$instances = $client->fetchInstances("get_NAME_Another_APP_From_EUREKA");
```

Contributing
============

[](#contributing)

If you find any bugs or have suggestions for new features, feel free to open an issue or submit a pull request on GitHub.

License
=======

[](#license)

Super Tools is open-source software licensed under the MIT license.

###  Health Score

16

—

LowBetter than 4% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity23

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/e594322f2894c8c70d5b0df7fa39e6bbfc9fe7452c531f4930c5e37ceb8c788a?d=identicon)[roshandelpoor](/maintainers/roshandelpoor)

---

Top Contributors

[![roshandelpoor](https://avatars.githubusercontent.com/u/16964040?v=4)](https://github.com/roshandelpoor "roshandelpoor (12 commits)")

### Embed Badge

![Health badge](/badges/roshandelpoor-register-php-app-in-eureka/health.svg)

```
[![Health](https://phpackages.com/badges/roshandelpoor-register-php-app-in-eureka/health.svg)](https://phpackages.com/packages/roshandelpoor-register-php-app-in-eureka)
```

###  Alternatives

[php-http/cache-plugin

PSR-6 Cache plugin for HTTPlug

25025.5M80](/packages/php-http-cache-plugin)[illuminate/http

The Illuminate Http package.

11937.2M6.5k](/packages/illuminate-http)[rdkafka/rdkafka

A PHP extension for Kafka

2.2k20.0k1](/packages/rdkafka-rdkafka)[httpsoft/http-message

Strict and fast implementation of PSR-7 and PSR-17

87930.4k113](/packages/httpsoft-http-message)[mezzio/mezzio-router

Router subcomponent for Mezzio

265.3M84](/packages/mezzio-mezzio-router)[serpapi/google-search-results-php

Get Google, Bing, Baidu, Ebay, Yahoo, Yandex, Home depot, Naver, Apple, Duckduckgo, Youtube search results via SerpApi.com

69122.6k](/packages/serpapi-google-search-results-php)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
