Client.php
1.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
<?php
/**
* Created by PhpStorm.
* User: Zip
* Date: 14/12/15
* Time: 上午2:02
*/
namespace Hood\Concurrent\Yar;
use Hood\Core\Root;
class Client extends Root
{
/**
* @var array
*/
private $_instances = array();
/**
* @var \Yar_Client
*/
private $client;
/**
* Set timeout to 3s
* @var int
*/
private $_timeout = 3000;
/**
* @param $uri
*/
public function __construct($uri)
{
parent::__construct();
$yarKey = md5($uri);
if (!isset($this->_instances[$yarKey])) {
$this->_instances[$yarKey] = new \Yar_Client($uri);
}
$this->client = $this->_instances[$yarKey];
}
/**
* 设置yar参数
* @param $name
* @param $value
*/
public function setOpt($name, $value)
{
$this->client->setOpt($name, $value);
return $this;
}
/**
* 数据包类型
* @param string $packagerType
*/
public function setPackager($packagerType = YAR_PACKAGER_PHP)
{
$this->client->setOpt(YAR_OPT_PACKAGER, $packagerType);
return $this;
}
/**
* 连接超时(毫秒为单位)
* @param $timeout
*/
public function setConnectTimeout($timeout = 1000)
{
$this->client->setOpt(YAR_OPT_CONNECT_TIMEOUT, $timeout);
return $this;
}
/**
* Set timeout to 3s
* 处理超时(毫秒为单位)
* @param $timeout
* @return $this
*/
public function setTimeout($timeout = 3000)
{
$this->client->setOpt(YAR_OPT_TIMEOUT, $timeout);
return $this;
}
/**
* @param $name
* @param array $arguments
* @return mixed
*/
public function __call($method, $parameters)
{
return $this->client->__call($method, $parameters);
}
}