PHP code example of teamones / etcd-discovery

1. Go to this page and download the library: Download teamones/etcd-discovery 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/ */

    

teamones / etcd-discovery example snippets



return [
    'discovery' => [
        'etcd_host' => env("etcd_host", ''),
        'server_name' => env("belong_system", ''),
        'server_uuid' => \Webpatser\Uuid\Uuid::generate()->string,
        'server_port' => env("host_port", 8080),
        'discovery_name' => ['im', 'saas', 'log', 'media'], // 要发现的服务名
        'log' => runtime_path() . '/logs/etcd.log', 
        'cache' => runtime_path() . '/logs'
    ]
];

// Worker::$onMasterReload = function () 上面增加

// 拉起etcd服务
if (class_exists('teamones\process\EtcdGoServer')) {
    \teamones\process\EtcdGoServer::exec();

    // Workerman 关闭杀死 etcd服务
    worker::$onMasterStop = function () {
        \teamones\process\EtcdGoServer::kill();
    };
}

// etcd 对象
    'etcd' => [
        'handler' => teamones\process\Etcd::class,
        'count' => 1
    ],



use teamones\Request;

$data = Request::connection()
            ->setHeader([
                'X-Userinfo' => request()->getXUserInfo(), // 一般需要传递用户信息
            ])
            ->setServerHost('im') // 请求服务名
            ->setRoute('options/get_business_mode') // 路由地址
            ->setMethod('POST') // 请求方式
            ->request();