1. Go to this page and download the library: Download xd/prime-rpc 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/ */
xd / prime-rpc example snippets
= new \Xd\PrimeRpc\Server\TcpServer('yur server name', '0.0.0.0', '9501', 20);
//bind receive event
\Xd\PrimeRpc\Server\IocEventServer::inject('receive', function($fd, $data){
//do something...
//output content at last
$output = ['code' => 0, 'msg' => 'ok', 'result' => ['title' => "test={$data['test']}"]];
return $output;
});
$server->start();
//connect host
$client = new Xd\PrimeRpc\Client\TcpClient('127.0.0.1', 9501);
//send data
$request1 = $client->request(['test' => '1']);
//send data
$request2 = $client->request(['test' => '2']);
//get the second response data
$res2 = $request2->receive();
print_r($res2);
//get the first response data
$res1 = $request1->receive();
print_r($res1);
= new \Xd\PrimeRpc\Server\HttpServer('yur server name', '0.0.0.0', '9501', 20);
//bind request event
\Xd\PrimeRpc\Server\IocEventServer::inject('request', function($request, $response){
//do something...
//output content at last
$output = ['code' => 0, 'msg' => 'ok', 'result' => ['title' => "test={$request->get['test']}"]];
return $output;
});
$server->start();
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.