RPC框架-yar學習
RPC采用客戶機/服務器模式。 請求程序就是一個客戶機,而服務提供程序就是一個服務器。首先,客戶機調用進程發送一個有進程參數的調用信息到服務進程,然后等待應答信息。在服務器端, 進程保持睡眠狀態直到調用信息的到達為止。當一個調用信息到達,服務器獲得進程參數,計算結果,發送答復信息,然后等待下一個調用信息,最后,客戶端調用進程接收答復信息,獲得進程結果,然后調用執行繼續進行。
php中RPC簡單框架感覺是YAR,嘗試自己寫一個案例,提前需要安裝yar框架,具體安裝方法上網搜搜:
服務器端:地址:http://html.com/yar/Operator.php 代碼:
class Operator { /** * Add two 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 will not be exposed * @param interge * @return interge */ protected function _add($a, $b) { return $a + $b; } } $server = new Yar_Server(new Operator()); $server->handle();
客戶的地址:http://html.com/yar/yar.php
代碼:
$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)));
打印結果為:
int(3)
int(5)
來自:http://www.cnblogs.com/hylaz/p/4473521.html
本文由用戶 me87re 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!