PHP code example of fuermao / eureka_php

1. Go to this page and download the library: Download fuermao/eureka_php library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

fuermao / eureka_php example snippets


$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'
]);

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

$client->register();

$client->deRegister();

$client->heartbeat();

$client->start();

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

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

class RoundRobinStrategy implements DiscoveryStrategy {

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

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

class MyProvider implements InstanceProvider {

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

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

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