PHPackages                             fuermao/eureka\_php - 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. [API Development](/categories/api)
4. /
5. fuermao/eureka\_php

ActiveLibrary[API Development](/categories/api)

fuermao/eureka\_php
===================

register php service with eureka service

V0.0.2(6y ago)07MITPHPPHP &gt;=7.1

Since Jan 7Pushed 6y ago1 watchersCompare

[ Source](https://github.com/fuermao/php_eureka)[ Packagist](https://packagist.org/packages/fuermao/eureka_php)[ RSS](/packages/fuermao-eureka-php/feed)WikiDiscussions master Synced today

READMEChangelogDependencies (1)Versions (3)Used By (0)

PHP Eureka
==========

[](#php-eureka)

说明
--

[](#说明)

该版本根据`piwvh/php-eureka`稍作配置上的优化而来。

使用说明
----

[](#使用说明)

### 安装

[](#安装)

使用composer依赖管理工具进行安装即可；

```
composer require "yckj/eureka_php"
```

### 使用

[](#使用)

> 该组件基本未改变原始用法，仅作了添加日志的操作。可参见原作者[piwvh/php-eureka](https://github.com/piwvh/php-eureka)

### Create Eureka Client

[](#create-eureka-client)

The very first thing you should do is to create an instance of `EurekaClient` using your 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 includes:

- `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 configuration after creating `EurekaClient` instance, using setter methods:

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

### Operations

[](#operations)

After creating EurekaClient instance, there will be multiple operations you can do:

- **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 determine the client is up (one-time heartbeat)

```
$client->heartbeat();
```

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

```
$client->start();
```

With 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` config. This interval time can be changed just like any other configuration item:

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

- **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 registered with Eureka. 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`, but 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

[](#local-registry-and-caching)

As you know, failure is inevitable, specially in cloud-native or distributed applications. So, sometimes Eureka may not be available duo to the failure. In this case, we should have a local registry of services to avoid cascading failures.

In the default behaviour, if Eureka is down, the `fetchInstance()` method fails and so the application throws and exception and can not continue to work. To solve this problem, you should create a local registry in your application.

There is an interface called `InstanceProvider` which you can make use of. You should implement `getInstance()` method of this interface and return 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 database
    }
}
```

In this example, we have cached the instances of the service in the database and are retrieving them from the database when Eureka is not available.

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 it. By adding this functionality, your application continues to work even when Eureka is down.

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

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

###  Health Score

23

—

LowBetter than 27% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity53

Maturing project, gaining track record

 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.

###  Release Activity

Cadence

Every ~0 days

Total

2

Last Release

2315d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/0aa5314bd8f79f356a4a9aadea60022a4abd31e7b61af0befe42ce5497fb2b83?d=identicon)[fuermao](/maintainers/fuermao)

---

Top Contributors

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

### Embed Badge

![Health badge](/badges/fuermao-eureka-php/health.svg)

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

###  Alternatives

[tencentcloud/tencentcloud-sdk-php

TencentCloudApi php sdk

3731.2M42](/packages/tencentcloud-tencentcloud-sdk-php)[convertkit/convertkitapi

Kit PHP SDK for the Kit API

2167.1k1](/packages/convertkit-convertkitapi)[mapado/rest-client-sdk

Rest Client SDK for hydra API

1125.9k2](/packages/mapado-rest-client-sdk)

PHPackages © 2026

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