1
|
|
|
<?php |
2
|
|
|
namespace PhpAmqpLib\Connection; |
3
|
|
|
|
4
|
|
|
use PhpAmqpLib\Wire\IO\StreamIO; |
5
|
|
|
|
6
|
|
|
class AMQPStreamConnection extends AbstractConnection |
7
|
|
|
{ |
8
|
|
|
/** |
9
|
|
|
* @param string $host |
10
|
|
|
* @param string $port |
11
|
|
|
* @param string $user |
12
|
|
|
* @param string $password |
13
|
|
|
* @param string $vhost |
14
|
|
|
* @param bool $insist |
15
|
|
|
* @param string $login_method |
16
|
|
|
* @param null $login_response |
17
|
|
|
* @param string $locale |
18
|
|
|
* @param float $connection_timeout |
19
|
|
|
* @param float $read_write_timeout |
20
|
|
|
* @param null $context |
21
|
|
|
* @param bool $keepalive |
22
|
|
|
* @param int $heartbeat |
23
|
|
|
*/ |
24
|
42 |
|
public function __construct( |
25
|
|
|
$host, |
26
|
|
|
$port, |
27
|
|
|
$user, |
28
|
|
|
$password, |
29
|
|
|
$vhost = '/', |
30
|
|
|
$insist = false, |
31
|
|
|
$login_method = 'AMQPLAIN', |
32
|
|
|
$login_response = null, |
33
|
|
|
$locale = 'en_US', |
34
|
|
|
$connection_timeout = 3.0, |
35
|
|
|
$read_write_timeout = 3.0, |
36
|
|
|
$context = null, |
37
|
|
|
$keepalive = false, |
38
|
|
|
$heartbeat = 0 |
39
|
|
|
) { |
40
|
42 |
|
$io = new StreamIO( |
41
|
42 |
|
$host, |
42
|
42 |
|
$port, |
43
|
42 |
|
$connection_timeout, |
44
|
42 |
|
$read_write_timeout, |
45
|
42 |
|
$context, |
46
|
42 |
|
$keepalive, |
47
|
14 |
|
$heartbeat |
48
|
28 |
|
); |
49
|
|
|
|
50
|
42 |
|
parent::__construct( |
51
|
42 |
|
$user, |
52
|
42 |
|
$password, |
53
|
42 |
|
$vhost, |
54
|
42 |
|
$insist, |
55
|
42 |
|
$login_method, |
56
|
42 |
|
$login_response, |
57
|
42 |
|
$locale, |
58
|
42 |
|
$io, |
59
|
42 |
|
$heartbeat, |
60
|
14 |
|
$connection_timeout |
61
|
28 |
|
); |
62
|
|
|
|
63
|
|
|
// save the params for the use of __clone, this will overwrite the parent |
64
|
36 |
|
$this->construct_params = func_get_args(); |
65
|
36 |
|
} |
66
|
|
|
|
67
|
|
|
protected static function try_create_connection($host, $port, $user, $password, $vhost, $options){ |
68
|
|
|
$insist = isset($options['insist']) ? |
69
|
|
|
$options['insist'] : false; |
70
|
|
|
$login_method = isset($options['login_method']) ? |
71
|
|
|
$options['login_method'] :'AMQPLAIN'; |
72
|
|
|
$login_response = isset($options['login_response']) ? |
73
|
|
|
$options['login_response'] : null; |
74
|
|
|
$locale = isset($options['locale']) ? |
75
|
|
|
$options['locale'] : 'en_US'; |
76
|
|
|
$connection_timeout = isset($options['connection_timeout']) ? |
77
|
|
|
$options['connection_timeout'] : 3.0; |
78
|
|
|
$read_write_timeout = isset($options['read_write_timeout']) ? |
79
|
|
|
$options['read_write_timeout'] : 3.0; |
80
|
|
|
$context = isset($options['context']) ? |
81
|
|
|
$options['context'] : null; |
82
|
|
|
$keepalive = isset($options['keepalive']) ? |
83
|
|
|
$options['keepalive'] : false; |
84
|
|
|
$heartbeat = isset($options['heartbeat']) ? |
85
|
|
|
$options['heartbeat'] : 0; |
86
|
|
|
return new static($host, |
87
|
|
|
$port, |
88
|
|
|
$user, |
89
|
|
|
$password, |
90
|
|
|
$vhost, |
91
|
|
|
$insist, |
92
|
|
|
$login_method, |
93
|
|
|
$login_response, |
94
|
|
|
$locale, |
95
|
|
|
$connection_timeout, |
96
|
|
|
$read_write_timeout, |
97
|
|
|
$context, |
98
|
|
|
$keepalive, |
99
|
|
|
$heartbeat); |
100
|
|
|
} |
101
|
|
|
} |
102
|
|
|
|