You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- instate operation error checks in php_mrloop_writev_cb and php_mrloop_readv_cb callbacks
- register global TCP connection data buffer size
- add connection data size and connection count parameters to tcpServer() function
- duplicate client connection file descriptor in php_mrloop_tcp_server_recv callback
- add vector count and offset parameters to addReadStream() function
- add vector count parameter to addWriteStream() function
- change DEFAULT_STREAM_BUFF_LEN and DEFAULT_CONN_BUFF_LEN values
- define DEFAULT_VECTOR_COUNT, DEFAULT_READV_OFFSET and PHP_MRLOOP_MAX_TCP_CONNECTIONS
Copy file name to clipboardexpand all lines: README.md
+52-6
Original file line number
Diff line number
Diff line change
@@ -47,14 +47,22 @@ class Mrloop
47
47
public addReadStream(
48
48
resource $stream,
49
49
?int $nbytes,
50
+
?int $vcount,
51
+
?int $offset,
50
52
callable $callback,
51
53
): void
52
54
public addWriteStream(
53
55
resource $stream,
54
56
string $contents,
57
+
?int $vcount,
58
+
callable $callback,
59
+
): void
60
+
public tcpServer(
61
+
int $port,
62
+
?int $connections,
63
+
?int $nbytes,
55
64
callable $callback,
56
65
): void
57
-
public tcpServer(int $port, callable $callback): void
58
66
public writev(int|resource $fd, string $message): void
59
67
public static parseHttpRequest(string $request, int $headerlimit = 100): iterable
60
68
public static parseHttpResponse(string $response, int $headerlimit = 100): iterable
@@ -133,6 +141,8 @@ Hello, user
133
141
public Mrloop::addReadStream(
134
142
resource $stream,
135
143
?int $nbytes,
144
+
?int $vcount,
145
+
?int $offset,
136
146
callable $callback,
137
147
): void
138
148
```
@@ -144,7 +154,12 @@ Funnels file descriptor in readable stream into event loop and thence executes a
144
154
-**stream** (resource) - A userspace-defined readable stream.
145
155
> The file descriptor in the stream is internally given a non-blocking disposition.
146
156
-**nbytes** (int|null) - The number of bytes to read.
147
-
> Specifying `null` will condition the use of an 8KB buffer.
157
+
> Specifying `null` will condition the use of a 1KB buffer.
158
+
-**vcount** (int|null) - The number of read vectors to use.
159
+
> Specifying `null` will condition the use of 2 vectors.
160
+
> Any value north of `8` will likely result in an inefficient read.
161
+
-**offset** (int|null) - The point at which to start the read operation.
162
+
> Specifying `null` will condition the use of an offset of `0`.
148
163
-**callback** (callable) - The binary function through which the file's contents and read result code are propagated.
149
164
150
165
**Return value(s)**
@@ -159,12 +174,14 @@ $loop = Mrloop::init();
159
174
$loop->addReadStream(
160
175
$fd = \fopen('/path/to/file', 'r'),
161
176
null,
177
+
null,
178
+
null,
162
179
function (string $contents, int $res) use ($fd) {
163
180
if ($res === 0) {
164
181
echo \sprintf("%s\n", $contents);
165
-
166
-
\fclose($fd);
167
182
}
183
+
184
+
\fclose($fd);
168
185
},
169
186
);
170
187
@@ -184,6 +201,7 @@ File contents...
184
201
public Mrloop::addWriteStream(
185
202
resource $stream,
186
203
string $contents,
204
+
?int $vcount,
187
205
callable $callback,
188
206
): void
189
207
```
@@ -195,6 +213,9 @@ Funnels file descriptor in writable stream into event loop and thence executes a
195
213
-**stream** (resource) - A userspace-defined writable stream.
196
214
> The file descriptor in the stream is internally given a non-blocking disposition.
197
215
-**contents** (string) - The contents to write to the file descriptor.
216
+
-**vcount** (int|null) - The number of write vectors to use.
217
+
> Specifying `null` will condition the use of 2 vectors.
218
+
> Any value north of `8` will likely result in an inefficient write.
198
219
-**callback** (callable) - The unary function through which the number of written bytes is propagated.
199
220
200
221
**Return value(s)**
@@ -211,6 +232,7 @@ $file = '/path/to/file';
211
232
$loop->addWriteStream(
212
233
$fd = \fopen($file, 'w'),
213
234
"file contents...\n",
235
+
null,
214
236
function (int $nbytes) use ($fd, $file) {
215
237
echo \sprintf("Wrote %d bytes to %s\n", $nbytes, $file);
216
238
@@ -231,14 +253,25 @@ Wrote 18 bytes to /path/to/file
231
253
### `Mrloop::tcpServer`
232
254
233
255
```php
234
-
public Mrloop::tcpServer(int $port, callable $callback): void
256
+
public Mrloop::tcpServer(
257
+
int $port,
258
+
?int $connections,
259
+
?int $nbytes,
260
+
callable $callback,
261
+
): void
235
262
```
236
263
237
264
Instantiates a simple TCP server.
238
265
239
266
**Parameter(s)**
240
267
241
268
-**port** (int) - The port on which to listen for incoming connections.
269
+
-**connections** (int|null) - The maximum number of connections to accept.
270
+
> This parameter does not have any effect when a version of mrloop in which the `mr_tcp_server` function lacks the `max_conn` parameter is included in the compilation process.
271
+
> Specifying `null` will condition the use of a `1024` connection threshold.
272
+
-**nbytes** (int|null) - The maximum number of readable bytes for each connection.
273
+
> This setting is akin to the `client_max_body_size` option in NGINX.
274
+
> Specifying null will condition the use of an `8192` byte threshold.
242
275
-**callback** (callable) - The binary function with which to define a response to a client.
243
276
> Refer to the segment to follow for more information on the callback.
244
277
-**Callback parameters**
@@ -259,6 +292,8 @@ $loop = Mrloop::init();
259
292
260
293
$loop->tcpServer(
261
294
8080,
295
+
null,
296
+
null,
262
297
function (string $message, iterable $client) {
263
298
// print access log
264
299
echo \sprintf(
@@ -311,6 +346,8 @@ $loop = Mrloop::init();
311
346
312
347
$loop->tcpServer(
313
348
8080,
349
+
null,
350
+
null,
314
351
function (string $message, iterable $client) use ($loop) {
0 commit comments