1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace PhpAmqpLib\Connection; |
4
|
|
|
|
5
|
|
|
use PhpAmqpLib\Wire\IO\StreamIO; |
6
|
|
|
|
7
|
|
|
class AMQPStreamConnection 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 float $connection_timeout |
20
|
|
|
* @param float $read_write_timeout |
21
|
|
|
* @param resource|array|null $context |
22
|
|
|
* @param bool $keepalive |
23
|
|
|
* @param int $heartbeat |
24
|
|
|
* @param float $channel_rpc_timeout |
25
|
|
|
* @param string|AMQPConnectionConfig|null $ssl_protocol @deprecated |
26
|
|
|
* @param AMQPConnectionConfig|null $config |
27
|
|
|
* @throws \Exception |
28
|
30 |
|
*/ |
29
|
|
|
public function __construct( |
30
|
|
|
$host, |
31
|
|
|
$port, |
32
|
|
|
$user, |
33
|
|
|
$password, |
34
|
|
|
$vhost = '/', |
35
|
|
|
$insist = false, |
36
|
|
|
$login_method = 'AMQPLAIN', |
37
|
|
|
$login_response = null, |
38
|
|
|
$locale = 'en_US', |
39
|
|
|
$connection_timeout = 3.0, |
40
|
|
|
$read_write_timeout = 3.0, |
41
|
|
|
$context = null, |
42
|
|
|
$keepalive = false, |
43
|
|
|
$heartbeat = 0, |
44
|
|
|
$channel_rpc_timeout = 0.0, |
45
|
|
|
$ssl_protocol = null, |
46
|
|
|
?AMQPConnectionConfig $config = null |
47
|
30 |
|
) { |
48
|
1 |
|
if ($ssl_protocol !== null && $ssl_protocol instanceof AMQPConnectionConfig === false) { |
49
|
|
|
trigger_error( |
50
|
|
|
'$ssl_protocol parameter is deprecated, use stream_context_set_option($context, \'ssl\', \'crypto_method\', $ssl_protocol) instead (see https://www.php.net/manual/en/function.stream-socket-enable-crypto.php for possible values)', |
51
|
29 |
|
E_USER_DEPRECATED |
52
|
|
|
); |
53
|
|
|
} elseif ($ssl_protocol instanceof AMQPConnectionConfig) { |
54
|
|
|
$config = $ssl_protocol; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
if ($channel_rpc_timeout > $read_write_timeout) { |
58
|
|
|
throw new \InvalidArgumentException('channel RPC timeout must not be greater than I/O read-write timeout'); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
$io = new StreamIO( |
62
|
29 |
|
$host, |
63
|
|
|
$port, |
64
|
|
|
$connection_timeout, |
65
|
|
|
$read_write_timeout, |
66
|
|
|
$context, |
67
|
|
|
$keepalive, |
68
|
|
|
$heartbeat |
69
|
|
|
); |
70
|
|
|
|
71
|
|
|
parent::__construct( |
|
|
|
|
72
|
|
|
$user, |
73
|
|
|
$password, |
74
|
|
|
$vhost, |
75
|
|
|
$insist, |
76
|
|
|
$login_method, |
77
|
|
|
$login_response, |
78
|
28 |
|
$locale, |
79
|
|
|
$io, |
80
|
|
|
$heartbeat, |
81
|
|
|
$connection_timeout, |
82
|
|
|
$channel_rpc_timeout, |
83
|
|
|
$config |
84
|
|
|
); |
85
|
|
|
|
86
|
|
|
// save the params for the use of __clone, this will overwrite the parent |
87
|
|
|
$this->construct_params = func_get_args(); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* @deprecated Use AmqpConnectionFactory |
92
|
|
|
* @throws \Exception |
93
|
|
|
*/ |
94
|
|
|
protected static function try_create_connection($host, $port, $user, $password, $vhost, $options) |
95
|
|
|
{ |
96
|
|
|
$insist = isset($options['insist']) ? |
97
|
|
|
$options['insist'] : false; |
98
|
|
|
$login_method = isset($options['login_method']) ? |
99
|
|
|
$options['login_method'] : 'AMQPLAIN'; |
100
|
|
|
$login_response = isset($options['login_response']) ? |
101
|
|
|
$options['login_response'] : null; |
102
|
|
|
$locale = isset($options['locale']) ? |
103
|
|
|
$options['locale'] : 'en_US'; |
104
|
|
|
$connection_timeout = isset($options['connection_timeout']) ? |
105
|
|
|
$options['connection_timeout'] : 3.0; |
106
|
|
|
$read_write_timeout = isset($options['read_write_timeout']) ? |
107
|
|
|
$options['read_write_timeout'] : 3.0; |
108
|
|
|
$context = isset($options['context']) ? |
109
|
|
|
$options['context'] : null; |
110
|
|
|
$keepalive = isset($options['keepalive']) ? |
111
|
|
|
$options['keepalive'] : false; |
112
|
|
|
$heartbeat = isset($options['heartbeat']) ? |
113
|
|
|
$options['heartbeat'] : 60; |
114
|
|
|
$channel_rpc_timeout = isset($options['channel_rpc_timeout']) ? |
115
|
|
|
$options['channel_rpc_timeout'] : 0.0; |
116
|
|
|
return new static( |
117
|
|
|
$host, |
118
|
|
|
$port, |
119
|
|
|
$user, |
120
|
|
|
$password, |
121
|
|
|
$vhost, |
122
|
|
|
$insist, |
123
|
|
|
$login_method, |
124
|
|
|
$login_response, |
125
|
|
|
$locale, |
126
|
|
|
$connection_timeout, |
127
|
|
|
$read_write_timeout, |
128
|
|
|
$context, |
129
|
|
|
$keepalive, |
130
|
|
|
$heartbeat, |
131
|
|
|
$channel_rpc_timeout |
132
|
|
|
); |
133
|
|
|
} |
134
|
|
|
} |
135
|
|
|
|