RPC takes client/server mode. The requestor is a client, and the service provider is a server. First, the client call process sends a call message with process parameters to the service process, and then waits for the reply message. On the server side, the process stays asleep until the call information arrives. When a call arrives, the server obtains the process parameters, evaluates the result, sends a reply message, and then waits for the next invocation information, and finally, the client invokes the process to receive the reply message, obtains the process result, and then invokes execution to proceed.
PHP simple framework of RPC feel is Yar, try to write a case, in advance need to install the Yar framework, specific installation methods online Search:
Server-side: Address: http://html.com/yar/Operator.php code:
Class Operator { /** * add \ Operands * @param interge * @return interge * * Public function add ($a, $b) { return $this->_add ($a, $b); } /** * Sub * /Public Function Sub ($a, $b) { return $a-$b; } /** * Mul * * * public function Mul ($a, $b) { return $a * $b; } /** * Protected methods won't be exposed * @param interge * @return Interge * / Protected func tion _add ($a, $b) { return $a + $b; }} $server = new Yar_server (new Operator ()); $server->handle ();
Customer's address: http://html.com/yar/yar.php
Code:
$url = "http://html.com/yar/Operator.php"; $client = new Yar_client ($url); Var_dump ($client->add (1, 2)); Var_dump ($ Client->call ("Add", Array (3, 2)));
Printing results are:
Int (3) int (5)
RPC Framework-yar Learning