Yar_Client 类

(No version information available, might only be in Git)

简介

Yar RPC 框架的客户端。一个客户端绑定到单一的服务地址; 调用该对象上任意未定义的方法,都会以该方法名和给定的参数发起一次远程调用。

类摘要

class Yar_Client {
/* 属性 */
protected int $_protocol;
protected string $_uri;
protected ?array $_options;
protected bool $_running;
/* 方法 */
final public function __construct(string $uri, ?array $options = null)
public function call(string $method, array $arguments): mixed
public function getOpt(int $name): mixed
public function setOpt(int $name, mixed $value): Yar_Client|bool
}

属性

_protocol

只读。从服务地址推导出的协议类型,取值为 YAR_CLIENT_PROTOCOL_HTTPYAR_CLIENT_PROTOCOL_TCPYAR_CLIENT_PROTOCOL_UNIX 之一。

_uri

只读。创建该客户端时使用的服务地址。

_options

只读。一个 array,包含此客户端上已设置的选项, 以 YAR_OPT_* 常量作为键; 若没有设置过任何选项,则为 null

_running

只读。此客户端发起的某个调用当前是否正在进行中。

目录

添加备注

用户贡献的备注 1 note

up
-1
porschegt23 at foxmail dot com
10 years ago
A simple example on here:

server.php
<?php
class API {
   
    public function api($parameter = "", $option = "foo") {
          return $this->client_can_not_see($parameter);
    }
 
 
    public function doAdd($a = 0, $b = 0) {
          return $a+$b;
    }
   
    protected function client_can_not_see( $name ) {
      return "你好$name~";
    }
}

$service = new Yar_Server ( new API () );
$service->handle ();
?>
client.php
<?php
  $client = new Yar_Client("http://host/server.php");
  $result = $client->api("parameter");
  echo $result.'<hr>';
  echo $client->doAdd(10, 20);
?>