PHP code example of gemini / rpc-multiplex
1. Go to this page and download the library: Download gemini/rpc-multiplex 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' );
gemini / rpc-multiplex example snippets
declare (strict_types=1 );
use Hyperf \Server \Event ;
use Hyperf \Server \Server ;
return [
'servers' => [
[
'name' => 'rpc' ,
'type' => Server::SERVER_BASE,
'host' => '0.0.0.0' ,
'port' => 9502 ,
'sock_type' => SWOOLE_SOCK_TCP,
'callbacks' => [
Event::ON_RECEIVE => [Hyperf\RpcMultiplex\TcpServer::class, 'onReceive' ],
],
'settings' => [
'open_length_check' => true ,
'package_length_type' => 'N' ,
'package_length_offset' => 0 ,
'package_body_offset' => 4 ,
'package_max_length' => 1024 * 1024 * 2 ,
],
],
],
];
namespace App \RPC ;
use App \JsonRpc \CalculatorServiceInterface ;
use Hyperf \RpcMultiplex \Constant ;
use Hyperf \RpcServer \Annotation \RpcService ;
class CalculatorService implements CalculatorServiceInterface
{
}
declare (strict_types=1 );
return [
'consumers' => [
[
'name' => 'CalculatorService' ,
'service' => App\JsonRpc\CalculatorServiceInterface::class,
'id' => App\JsonRpc\CalculatorServiceInterface::class,
'protocol' => Hyperf\RpcMultiplex\Constant::PROTOCOL_DEFAULT,
'load_balancer' => 'random' ,
'nodes' => [
['host' => '127.0.0.1' , 'port' => 9502 ],
],
'options' => [
'connect_timeout' => 5.0 ,
'recv_timeout' => 5.0 ,
'settings' => [
'package_max_length' => 1024 * 1024 * 2 ,
],
'retry_count' => 2 ,
'retry_interval' => 100 ,
'client_count' => 4 ,
'heartbeat' => 30 ,
],
],
],
];