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
+41-6
Original file line number
Diff line number
Diff line change
@@ -47,14 +47,21 @@ 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,
55
57
callable $callback,
56
58
): void
57
-
public tcpServer(int $port, callable $callback): void
59
+
public tcpServer(
60
+
int $port,
61
+
?int $connections,
62
+
?int $nbytes,
63
+
callable $callback,
64
+
): void
58
65
public writev(int|resource $fd, string $message): void
59
66
public static parseHttpRequest(string $request, int $headerlimit = 100): iterable
60
67
public static parseHttpResponse(string $response, int $headerlimit = 100): iterable
@@ -133,6 +140,8 @@ Hello, user
133
140
public Mrloop::addReadStream(
134
141
resource $stream,
135
142
?int $nbytes,
143
+
?int $vcount,
144
+
?int $offset,
136
145
callable $callback,
137
146
): void
138
147
```
@@ -144,7 +153,12 @@ Funnels file descriptor in readable stream into event loop and thence executes a
144
153
-**stream** (resource) - A userspace-defined readable stream.
145
154
> The file descriptor in the stream is internally given a non-blocking disposition.
146
155
-**nbytes** (int|null) - The number of bytes to read.
147
-
> Specifying `null` will condition the use of an 8KB buffer.
156
+
> Specifying `null` will condition the use of a 1KB buffer.
157
+
-**vcount** (int|null) - The number of read vectors to use.
158
+
> Specifying `null` will condition the use of 2 vectors.
159
+
> Any value north of `8` will likely result in an inefficient read.
160
+
-**offset** (int|null) - The point at which to start the read operation.
161
+
> Specifying `null` will condition the use of an offset of `0`.
148
162
-**callback** (callable) - The binary function through which the file's contents and read result code are propagated.
149
163
150
164
**Return value(s)**
@@ -158,13 +172,15 @@ $loop = Mrloop::init();
158
172
159
173
$loop->addReadStream(
160
174
$fd = \fopen('/path/to/file', 'r'),
161
-
null,
175
+
null, // 1024
176
+
null, // 2
177
+
null, // 0
162
178
function (string $contents, int $res) use ($fd) {
163
179
if ($res === 0) {
164
180
echo \sprintf("%s\n", $contents);
165
-
166
-
\fclose($fd);
167
181
}
182
+
183
+
\fclose($fd);
168
184
},
169
185
);
170
186
@@ -184,6 +200,7 @@ File contents...
184
200
public Mrloop::addWriteStream(
185
201
resource $stream,
186
202
string $contents,
203
+
?int $vcount,
187
204
callable $callback,
188
205
): void
189
206
```
@@ -195,6 +212,9 @@ Funnels file descriptor in writable stream into event loop and thence executes a
195
212
-**stream** (resource) - A userspace-defined writable stream.
196
213
> The file descriptor in the stream is internally given a non-blocking disposition.
197
214
-**contents** (string) - The contents to write to the file descriptor.
215
+
-**vcount** (int|null) - The number of write vectors to use.
216
+
> Specifying `null` will condition the use of 2 vectors.
217
+
> Any value north of `8` will likely result in an inefficient write.
198
218
-**callback** (callable) - The unary function through which the number of written bytes is propagated.
199
219
200
220
**Return value(s)**
@@ -211,6 +231,7 @@ $file = '/path/to/file';
211
231
$loop->addWriteStream(
212
232
$fd = \fopen($file, 'w'),
213
233
"file contents...\n",
234
+
null,
214
235
function (int $nbytes) use ($fd, $file) {
215
236
echo \sprintf("Wrote %d bytes to %s\n", $nbytes, $file);
216
237
@@ -231,14 +252,25 @@ Wrote 18 bytes to /path/to/file
231
252
### `Mrloop::tcpServer`
232
253
233
254
```php
234
-
public Mrloop::tcpServer(int $port, callable $callback): void
255
+
public Mrloop::tcpServer(
256
+
int $port,
257
+
?int $connections,
258
+
?int $nbytes,
259
+
callable $callback,
260
+
): void
235
261
```
236
262
237
263
Instantiates a simple TCP server.
238
264
239
265
**Parameter(s)**
240
266
241
267
-**port** (int) - The port on which to listen for incoming connections.
268
+
-**connections** (int|null) - The maximum number of connections to accept.
269
+
> 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.
270
+
> Specifying `null` will condition the use of a `1024` connection threshold.
271
+
-**nbytes** (int|null) - The maximum number of readable bytes for each connection.
272
+
> This setting is akin to the `client_max_body_size` option in NGINX.
273
+
> Specifying null will condition the use of an `8192` byte threshold.
242
274
-**callback** (callable) - The binary function with which to define a response to a client.
243
275
> Refer to the segment to follow for more information on the callback.
244
276
-**Callback parameters**
@@ -259,6 +291,8 @@ $loop = Mrloop::init();
259
291
260
292
$loop->tcpServer(
261
293
8080,
294
+
null,
295
+
null,
262
296
function (string $message, iterable $client) {
263
297
// print access log
264
298
echo \sprintf(
@@ -311,6 +345,7 @@ $loop = Mrloop::init();
311
345
312
346
$loop->tcpServer(
313
347
8080,
348
+
null,
314
349
function (string $message, iterable $client) use ($loop) {
0 commit comments