PHP code example of mix / micro

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

    

mix / micro example snippets


$server = new \Mix\Grpc\Server('0.0.0.0'); // 默认会随机分配端口,也可以指定
$server->register(SayService::class);

$registry = new \Mix\Micro\Etcd\Registry('http://127.0.0.1:2379/v3');

$config = new \Mix\Micro\Etcd\Config('http://127.0.0.1:2379/v3');
$config->listen($eventDispatcher); // PSR-14 Event Dispatcher

use Mix\Micro\Micro;

Micro::newService(
    Micro::server($server),
    Micro::registry($registry),
    Micro::config($config),
    Micro::logger($logger), // PSR-3 Logger
    Micro::version('latest'),
    Micro::metadata(['foo' => 'bar'])
)->run();

[2020-05-21 21:01:18] API.INFO: Server started [0.0.0.0:51438]
[2020-05-21 21:01:18] API.INFO: Register service [php.micro.grpc.greeter-2938109e-9b63-11ea-80bd-000057bdb82e]