-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathext_zmq.php
214 lines (192 loc) · 6.48 KB
/
ext_zmq.php
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
<?hh
class ZMQ {
}
class ZMQContext {
/**
* Build a new ZMQContext.
* @return void
*/
<<__Native>>
public function __construct(int $io_threads = 1): void;
/**
* Construct a new ZMQ object. The extending class must call this method.
* The type is one of the ZMQ::SOCKET_* constants.
* Persistent id allows reusing the socket over multiple requests.
* If persistent_id parameter is specific the type parameter is ignored and the
* socket is of type that it was initially created with. Persistent context must
* be enabled for persistent_id to work. Setting incorrect socket type might
* cause failure later in connect/bind/setSockOpt.
*
* @param integer $type The type of the socket
* @param string $persistent_id The persistent id. Can be used to create
* persistent connections
* @param function $on_new_socket Called when a new socket is created
* @throws ZMQException
* @return ZMQSocket
*/
public function getSocket(int $type, string $persistent_id = null, Closure $on_new_socket = null) : ZMQSocket
{
// Fix for "Warning: __construct() expects parameter 4 to be object, NULL given"
if ($on_new_socket)
{
$socket = new ZMQSocket($this, $type, $persistent_id, $on_new_socket);
}
else
{
$socket = new ZMQSocket($this, $type, $persistent_id);
}
return $socket;
}
/**
* Whether the context is persistent
*
* @return boolean
*/
public function isPersistent()
{
return true;
}
}
class ZMQSocket {
/**
* Construct a new ZMQ object. The extending class must call this method.
* The type is one of the ZMQ::SOCKET_* constants.
* Persistent id allows reusing the socket over multiple requests.
* If persistent_id parameter is specific the type parameter is ignored and the
* socket is of type that it was initially created with. Persistent context must
* be enabled for persistent_id to work. Setting incorrect socket type might
* cause failure later in connect/bind/setSockOpt.
*
* @param ZMQContext $context ZMQContext to build this object
* @param integer $type The type of the socket
* @param string $persistent_id The persistent id. Can be used to create
* persistent connections
* @param function $on_new_socket Called when a new socket is created
* @throws ZMQException
* @return void
*/
<<__Native>>
public function __construct(ZMQContext $context, int $type, string $persistent_id = null, Closure $on_new_socket = null): void;
/**
* Sends a message to the queue.
*
* @param string $message The message to send
* @param integer $flags self::MODE_NOBLOCK or 0
* @throws ZMQException if sending message fails
*
* @return mixed
*/
<<__Native>>
public function send(string $message, int $flags = 0): mixed;
/**
* Receives a message from the queue.
*
* @param integer $flags self::MODE_NOBLOCK or 0
* @throws ZMQException if receiving fails.
*
* @return mixed
*/
<<__Native>>
public function recv(int $flags = 0): mixed;
/**
* Connect the socket to a remote endpoint. For more information about the dsn
* see http://api.zeromq.org/zmq_connect.html. By default the method does not
* try to connect if it has been already connected to the address specified by $dsn.
*
* @param string $dsn The connect dsn
* @param boolean $force Tries to connect to end-point even if the object is already connected to the $dsn
*
* @throws ZMQException If connection fails
* @return ZMQSocket
*/
<<__Native>>
public function connect(string $dsn, bool $force = false): ZMQSocket;
/**
* Disconnect the socket from a previously connected remote endpoint.
*
* @param string $dsn The disconnect dsn
*
* @throws ZMQException If disconnecting fails
* @return ZMQSocket
*/
<<__Native>>
public function disconnect(string $dsn): ZMQSocket;
/**
*
* Binds the socket to an end-point. For more information about the dsn see
* http://api.zeromq.org/zmq_connect.html. By default the method does not
* try to bind if it has been already bound to the address specified by $dsn.
*
* @param string $dsn The bind dsn
* @param boolean $force Tries to bind to end-point even if the object is already bound to the $dsn
*
* @throws ZMQException if binding fails
* @return ZMQSocket
*/
<<__Native>>
public function bind(string $dsn, bool $force = false): ZMQSocket;
/**
*
* Unbind the socket from an endpoint.
*
* @param string $dsn The unbind dsn
*
* @throws ZMQException if binding fails
* @return ZMQSocket
*/
<<__Native>>
public function unbind(string $dsn): ZMQSocket;
/**
* Sets a socket option. For more information about socket options see
* http://api.zeromq.org/zmq_setsockopt.html
*
* @param integer $key The option key
* @param mixed $value The option value
*
* @throws ZMQException
* @return ZMQ
*/
<<__Native>>
public function setSockOpt(int $key, mixed $value): ZMQSocket;
/**
* Gets a socket option. This method is available if ZMQ extension
* has been compiled against ZMQ version 2.0.7 or higher
*
* @since 0MQ 2.0.7
* @param integer $key The option key
*
* @throws ZMQException
* @return mixed
*/
public function getSockOpt(int $key) {}
/**
* Get endpoints where the socket is connected to. The return array
* contains two sub-arrays: 'connect' and 'bind'
*
* @throws ZMQException
* @return array
*/
public function getEndpoints() {}
/**
* Return the socket type. Returns one of ZMQ::SOCKET_* constants
*
* @throws ZMQException
* @return integer
*/
<<__Native>>
public function getSocketType(): int;
/**
* Whether the socket is persistent
*
* @return boolean
*/
public function isPersistent() {
return false;
}
}
class ZMQException extends Exception {
}
class ZMQContextException extends ZMQException {
}
class ZMQSocketException extends ZMQException {
}