1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace PhpAmqpLib\Connection; |
4
|
|
|
|
5
|
|
|
use PhpAmqpLib\Wire\IO\SocketIO; |
6
|
|
|
|
7
|
|
|
class AMQPSocketConnection extends AbstractConnection |
8
|
|
|
{ |
9
|
|
|
/** |
10
|
|
|
* @param string $host |
11
|
|
|
* @param int $port |
12
|
|
|
* @param string $user |
13
|
|
|
* @param string $password |
14
|
|
|
* @param string $vhost |
15
|
|
|
* @param bool $insist |
16
|
|
|
* @param string $login_method |
17
|
|
|
* @param null $login_response @deprecated |
|
|
|
|
18
|
|
|
* @param string $locale |
19
|
|
|
* @param int|float $read_timeout |
20
|
|
|
* @param bool $keepalive |
21
|
|
|
* @param int $write_timeout |
22
|
|
|
* @param int $heartbeat |
23
|
|
|
* @param float $channel_rpc_timeout |
24
|
|
|
* @param AMQPConnectionConfig|null $config |
25
|
|
|
* @throws \Exception |
26
|
|
|
*/ |
27
|
21 |
|
public function __construct( |
28
|
|
|
$host, |
29
|
|
|
$port, |
30
|
|
|
$user, |
31
|
|
|
$password, |
32
|
|
|
$vhost = '/', |
33
|
|
|
$insist = false, |
34
|
|
|
$login_method = 'AMQPLAIN', |
35
|
|
|
$login_response = null, |
36
|
|
|
$locale = 'en_US', |
37
|
|
|
$read_timeout = 3, |
38
|
|
|
$keepalive = false, |
39
|
|
|
$write_timeout = 3, |
40
|
|
|
$heartbeat = 0, |
41
|
|
|
$channel_rpc_timeout = 0.0, |
42
|
|
|
?AMQPConnectionConfig $config = null |
43
|
|
|
) { |
44
|
21 |
|
if ($channel_rpc_timeout > $read_timeout) { |
45
|
1 |
|
throw new \InvalidArgumentException('channel RPC timeout must not be greater than I/O read timeout'); |
46
|
|
|
} |
47
|
|
|
|
48
|
20 |
|
$io = new SocketIO($host, $port, $read_timeout, $keepalive, $write_timeout, $heartbeat, $config); |
49
|
|
|
|
50
|
20 |
|
parent::__construct( |
|
|
|
|
51
|
|
|
$user, |
52
|
|
|
$password, |
53
|
|
|
$vhost, |
54
|
|
|
$insist, |
55
|
|
|
$login_method, |
56
|
|
|
$login_response, |
57
|
|
|
$locale, |
58
|
|
|
$io, |
59
|
|
|
$heartbeat, |
60
|
20 |
|
max($read_timeout, $write_timeout), |
61
|
|
|
$channel_rpc_timeout, |
62
|
|
|
$config |
63
|
|
|
); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @deprecated Use AmqpConnectionFactory |
68
|
|
|
* @throws \Exception |
69
|
|
|
*/ |
70
|
|
|
protected static function try_create_connection($host, $port, $user, $password, $vhost, $options) |
71
|
|
|
{ |
72
|
|
|
$insist = isset($options['insist']) ? |
73
|
|
|
$options['insist'] : false; |
74
|
|
|
$login_method = isset($options['login_method']) ? |
75
|
|
|
$options['login_method'] : 'AMQPLAIN'; |
76
|
|
|
$login_response = isset($options['login_response']) ? |
77
|
|
|
$options['login_response'] : null; |
78
|
|
|
$locale = isset($options['locale']) ? |
79
|
|
|
$options['locale'] : 'en_US'; |
80
|
|
|
$read_timeout = isset($options['read_timeout']) ? |
81
|
|
|
$options['read_timeout'] : 3; |
82
|
|
|
$keepalive = isset($options['keepalive']) ? |
83
|
|
|
$options['keepalive'] : false; |
84
|
|
|
$write_timeout = isset($options['write_timeout']) ? |
85
|
|
|
$options['write_timeout'] : 3; |
86
|
|
|
$heartbeat = isset($options['heartbeat']) ? |
87
|
|
|
$options['heartbeat'] : 0; |
88
|
|
|
$channel_rpc_timeout = isset($options['channel_rpc_timeout']) ? |
89
|
|
|
$options['channel_rpc_timeout'] : 0.0; |
90
|
|
|
return new static( |
91
|
|
|
$host, |
92
|
|
|
$port, |
93
|
|
|
$user, |
94
|
|
|
$password, |
95
|
|
|
$vhost, |
96
|
|
|
$insist, |
97
|
|
|
$login_method, |
98
|
|
|
$login_response, |
99
|
|
|
$locale, |
100
|
|
|
$read_timeout, |
101
|
|
|
$keepalive, |
102
|
|
|
$write_timeout, |
103
|
|
|
$heartbeat, |
104
|
|
|
$channel_rpc_timeout |
105
|
|
|
); |
106
|
|
|
} |
107
|
|
|
} |
108
|
|
|
|