summaryrefslogtreecommitdiff
path: root/tests/http/slow-client.php
blob: 1eaa7bc8d996b38dafdcf41d127f1234adb32d78 (plain)
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
<?php

use Spiral\Goridge;
use Spiral\RoadRunner;

ini_set('display_errors', 'stderr');
require dirname(__DIR__) . "/vendor/autoload.php";

if (count($argv) < 3) {
    die("need 2 arguments");
}

[$test, $goridge, $bootDelay] = [$argv[1], $argv[2], $argv[3]];
usleep($bootDelay * 1000);

switch ($goridge) {
    case "pipes":
        $relay = new Goridge\StreamRelay(STDIN, STDOUT);
        break;

    case "tcp":
        $relay = new Goridge\SocketRelay("127.0.0.1", 9007);
        break;

    case "unix":
        $relay = new Goridge\SocketRelay(
            "sock.unix",
            null,
            Goridge\SocketRelay::SOCK_UNIX
        );
        break;

    default:
        die("invalid protocol selection");
}

$psr7 = new RoadRunner\Http\PSR7Worker(
    new RoadRunner\Worker($relay),
    new \Nyholm\Psr7\Factory\Psr17Factory(),
    new \Nyholm\Psr7\Factory\Psr17Factory(),
    new \Nyholm\Psr7\Factory\Psr17Factory()
);

require_once sprintf("%s/%s.php", __DIR__, $test);

while ($req = $psr7->waitRequest()) {
    try {
        $psr7->respond(handleRequest($req, new \Nyholm\Psr7\Response()));
    } catch (\Throwable $e) {
        $psr7->getWorker()->error((string) $e);
    }
}