1. Go to this page and download the library: Download makaronnik/amphp-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/ */
makaronnik / amphp-rpc example snippets
use Amp\Promise;
interface SimpleCalcInterface
{
public function add(int $a, int $b): Promise; // remote procedure add() API
}
use Amp\Promise;
use function Amp\call;
class SimpleCalc implements SimpleCalcInterface
{
public function add(int $a, int $b): Promise // remote procedure add() implementation
{
return call(fn (): int => $a + $b); // returns Promise<int>
}
}
$registry = new RpcRegistry();
$registry->registerRemoteObject(SimpleCalcInterface::class, SimpleCalc::class);
$requestHandler = new RpcRequestHandler(new NativeSerializer(), $registry);
$rpcServer = (new RpcServerFactory(8181, $registry, $requestHandler))->getRpcServer();
yield $rpcServer->start();