forked from laravel/octane
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathroadrunner-worker
executable file
·66 lines (56 loc) · 1.91 KB
/
roadrunner-worker
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/usr/bin/env php
<?php
use Laminas\Diactoros\ServerRequestFactory;
use Laminas\Diactoros\StreamFactory;
use Laminas\Diactoros\UploadedFileFactory;
use Laravel\Octane\ApplicationFactory;
use Laravel\Octane\RequestContext;
use Laravel\Octane\RoadRunner\RoadRunnerClient;
use Laravel\Octane\Stream;
use Laravel\Octane\Worker;
use Psr\Http\Message\ServerRequestInterface;
use Spiral\Goridge\Exception\RelayException;
use Spiral\Goridge\Relay;
use Spiral\RoadRunner\Http\PSR7Worker;
use Spiral\RoadRunner\Worker as RoadRunnerWorker;
$basePath = require __DIR__.'/bootstrap.php';
/*
|--------------------------------------------------------------------------
| Start The Octane Worker
|--------------------------------------------------------------------------
|
| Next we will start the Octane worker, which is a long running process to
| handle incoming requests to the application. Octane can intercept the
| incoming requests and proxy them to the Laravel application for us.
|
*/
$roadRunnerClient = new RoadRunnerClient($psr7Client = new PSR7Worker(
new RoadRunnerWorker(Relay::create($_ENV['LARAVEL_OCTANE_ROADRUNNER_RELAY'] ?? 'pipes')),
new ServerRequestFactory,
new StreamFactory,
new UploadedFileFactory,
));
$worker = null;
try {
while ($psr7Request = $psr7Client->waitRequest()) {
$worker = $worker ?: tap((new Worker(
new ApplicationFactory($basePath), $roadRunnerClient
)))->boot();
if (! $psr7Request instanceof ServerRequestInterface) {
break;
}
[$request, $context] = $roadRunnerClient->marshalRequest(new RequestContext([
'psr7Request' => $psr7Request,
]));
$worker->handle($request, $context);
}
} catch (Throwable $e) {
if (! $e instanceof RelayException) {
$worker ? report($e) : Stream::shutdown($e);
}
exit(1);
} finally {
if (! is_null($worker)) {
$worker->terminate();
}
}