PHP并行 RPC 框架,Yar-1.0.0 发布

jopen 12年前

Yar-1.0.0发布 目前文档暂缺。http://pecl.php.net/package/yar

Yar 是一个支持多种打包协议的, 并行的RPC框架.

它基于HTTP协议, 在libcurl基础上开发而成

简单的Server:

  1.  
  2. class API {
  3.     /**
  4. * the doc info will be generated automatically into service info page.
  5. * @params
  6. * @return
  7. */
  8.     public function api($parameter, $option = "foo") {
  9.     }
  10.  
  11.     protected function client_can_not_see() {
  12.     }
  13. }
  14.  
  15. $service = new Yar_Server(new API());
  16. $service->handle();
  17. ?>

简单调用:

  1. $client = new Yar_Client("http://host/api/");
  2. $result = $client->api("parameter);
  3. ?>

并行调用:

 

  1. function callback($retval, $callinfo) {
  2.      var_dump($retval);
  3. }
  4.  
  5. Yar_Concurrent_Client::call("http://host/api/", "api", array("parameters"), "callback");
  6. Yar_Concurrent_Client::call("http://host/api/", "api", array("parameters"), "callback");
  7. Yar_Concurrent_Client::call("http://host/api/", "api", array("parameters"), "callback");
  8. Yar_Concurrent_Client::call("http://host/api/", "api", array("parameters"), "callback");
  9. Yar_Concurrent_Client::loop(); //send
  10. ?>

更多信息参看: Yar at Github