942d254ea8b316b0eb188bfba00a3f3f1e0c9727
[m6w6/ext-http] / tests / helper / pipeline.inc
1 <?php
2
3 include "server.inc";
4
5 function respond($client, $msg) {
6 $r = new http\Env\Response;
7 $r->setEnvRequest($msg)
8 ->setHeader("X-Req", $msg->getRequestUrl())
9 ->send($client);
10 }
11
12 serve(function($client) {
13 $count = trim(fgets(STDIN));
14 logger("Expecting %d messages", $count);
15 /* the peek message */
16 respond($client, new http\Message($client, false));
17 logger("Handled the peek request");
18 /* pipelined messages */
19 $req = array();
20 for ($i=0; $i < $count; ++ $i) {
21 $req[] = new http\Message($client, false);
22 logger("Read request no. %d", $i+1);
23 }
24 foreach ($req as $i => $msg) {
25 respond($client, $msg);
26 logger("Sent response no. %d", $i+1);
27 }
28 });