summaryrefslogtreecommitdiff
path: root/tests/test_worker.php
blob: d0cf7bb322772bcf289bdb180e5a1410961223fe (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
<?php

use Spiral\RoadRunner;
use Nyholm\Psr7;

include "vendor/autoload.php";

$worker = RoadRunner\Worker::create();
$psrFactory = new Psr7\Factory\Psr17Factory();

$worker = new RoadRunner\Http\PSR7Worker($worker, $psrFactory, $psrFactory, $psrFactory);
$counter = 0;

while ($req = $worker->waitRequest()) {
    try {
        $rsp = new Psr7\Response();

        if ($req->getUri()->getPath() !== '/') {
            $worker->respond($rsp->withStatus(404));
            continue;
        }

        $rsp->getBody()->write('Hello world!');
        $rsp->getBody()->write(PHP_EOL);
        $rsp->getBody()->write((string)$counter++);

        $worker->respond($rsp);

    } catch (\Throwable $e) {
        $worker->getWorker()->error((string)$e);
    }
}