PHP code example of midoks / php-eureka-client

1. Go to this page and download the library: Download midoks/php-eureka-client 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/ */

    

midoks / php-eureka-client example snippets


use Eureka\Client;

// We will use app name and instance id for making requests below.
$client = new \Euraka\Client($this->host, $this->port, $this->context);



// Create eureka v2 client.
$client = new EurekaClient('localhost', 8080);

// Create eureka v1 client.
$client = new EurekaClient('localhost', 8080, 'eureka');

try {
  // Register new application instance.
  $response = $client->registerApp($appName, $instance);

  // Query for all instances.
  $allApps = $client->getAllApps();

  // Query for all application instances.
  $app = $client->getApp($appName);

  // Query for a specific application instance.
  $appInstance = $client->getAppInstance($appName, $instanceId);

  // Query for a specific instance.
  $instance = $client->getInstance($instanceId);

  // Send application instance heartbeat.
  $response = $client->heartBeat($appName, $instanceId);

  // Take instance out of service.
  $response = $client->takeInstanceOut($appName, $instanceId);

  // Put instance back into service.
  $response = $client->putInstanceBack($appName, $instanceId);

  // Update metadata.
  $response = $client->updateAppInstanceMetadata($appName, $instanceId, [
    'new_key' => 'new_value',
  ]);

  // Query for all instances under a particular vip address/
  $instances = $client->getInstancesByVipAddress('test_vip_address');

  // Query for all instances under a particular secure vip address.
  $instances = $client->getInstancesBySecureVipAddress('test_secure_vip_address');

  // De-register application instance.
  $response = $client->deRegisterApp($appName, $instanceId);
}
catch (Exception $e) {
  echo $e->getMessage() . PHP_EOL;
}

composer