1. Go to this page and download the library: Download bit3/remote-objects 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/ */
bit3 / remote-objects example snippets
class RemoteObject
{
public function reply($name)
{
return 'Hello ' . $name;
}
}
$transport = new RemoteObjects\Transport\UnixSocketServer('/tmp/socket.server');
$encoder = new RemoteObjects\Encode\JsonRpc20Encoder();
$target = new RemoteObject();
$server = new RemoteObjects\Server(
$transport,
$encoder,
$target
);
$server->handle();
$transport = new RemoteObjects\Transport\UnixSocketClient('/tmp/socket.client', '/tmp/socket.server');
$encoder = new RemoteObjects\Encode\JsonRpc20Encoder();
$server = new RemoteObjects\Client(
$transport,
$encoder
);
$result = $server->invoke('reply', 'Tristan');
echo $result; // -> "Hello Tristan"
interface MyRemote
{
public function remoteMethod();
}
$remote = $client->castAsRemoteObject('MyRemote');
class MyRemote
{
public function remoteMethod()
{
// ...
}
}
$remote = $client->castAsRemoteObject('MyRemote');
$jsonEncoder = new RemoteObjects\Encode\JsonRpc20Encoder();
$encoder = new RemoteObjects\Encode\AesEncoder(
$jsonEncoder,
'<add your pre-shared key here>'
);
$jsonEncoder = new RemoteObjects\Encode\JsonRpc20Encoder();
$encoder = new RemoteObjects\Encode\RsaEncoder(
$jsonEncoder,
'<add client public key here>',
'<add server private key here>'
);
$jsonEncoder = new RemoteObjects\Encode\JsonRpc20Encoder();
$encoder = new RemoteObjects\Encode\RsaEncoder(
$jsonEncoder,
'<add server public key here>',
'<add client private key here>'
);
$logger = new \Monolog\Logger('RemoteObjects');
$logger->pushHandler(new StreamHandler('php://stderr', Logger::ERROR));
$transport->setLogger($logger);
$encoder->setLogger($logger);
$server->setLogger($logger);
// or
$client->setLogger($logger);
user -> Client::invoke($method, $params)
\
\--> Encoder::encodeMethod($method, $params)
/
$request <-/
\
\--> Transport\Client::request($request)
|
|
HTTP or something else :-)
|
V
Transport\Server::receive()
/
$request <-/
\
\--> Encoder::decodeMethod($request)
/
[$method, $params] <-/
\
\--> Server::invokeArgs($method, $params)
\
\--> $target->$method($params..)
/
$result <--/
\
\--> Encoder::encodeResult($result)
/
$response <--/
\
\--> Transport\Server:respond($response)
|
|
All the way back
|
V
Transport\Client::request(...)
/
$response <--/
\
\--> Encoder::decodeResult($response)
/
$result <--/
/
user <--/
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.