-
Notifications
You must be signed in to change notification settings - Fork 107
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
73 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
version: '3' | ||
server: | ||
command: "php web/api.php" | ||
|
||
http: | ||
address: 0.0.0.0:8080 | ||
pool: | ||
num_workers: ${NUM_WORKERS} | ||
|
||
rpc: | ||
listen: tcp://127.0.0.1:6001 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
FROM ghcr.io/roadrunner-server/roadrunner:2023.2.1 AS roadrunner | ||
FROM composer:2.4.4 AS composer | ||
FROM php:8.1-cli | ||
COPY --from=composer /usr/bin/composer /usr/bin/composer | ||
COPY --from=roadrunner /usr/bin/rr /usr/local/bin/rr | ||
RUN docker-php-ext-install -j$(nproc) sockets && apt update && apt install unzip | ||
WORKDIR /app | ||
COPY . /app | ||
RUN composer install --prefer-dist --optimize-autoloader && composer require --prefer-dist --optimize-autoloader spiral/roadrunner-http nyholm/psr7 | ||
ENTRYPOINT rr --WorkDir /app --debug serve | ||
EXPOSE 8080 | ||
ENV NUM_WORKERS 4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?php | ||
require __DIR__ . '/../vendor/autoload.php'; | ||
|
||
use Nyholm\Psr7\Response; | ||
use Nyholm\Psr7\Factory\Psr17Factory; | ||
|
||
use Spiral\RoadRunner\Worker; | ||
use Spiral\RoadRunner\Http\PSR7Worker; | ||
|
||
// Create new RoadRunner worker from global environment | ||
$worker = Worker::create(); | ||
|
||
// Create common PSR-17 HTTP factory | ||
$factory = new Psr17Factory(); | ||
|
||
$psr7 = new PSR7Worker($worker, $factory, $factory, $factory); | ||
|
||
while (true) { | ||
try { | ||
$request = $psr7->waitRequest(); | ||
} catch (\Throwable $e) { | ||
// Although the PSR-17 specification clearly states that there can be | ||
// no exceptions when creating a request, however, some implementations | ||
// may violate this rule. Therefore, it is recommended to process the | ||
// incoming request for errors. | ||
// | ||
// Send "Bad Request" response. | ||
$psr7->respond(new Response(400)); | ||
continue; | ||
} | ||
|
||
try { | ||
// Here is where the call to your application code will be located. | ||
// For example: | ||
// $response = $app->send($request); | ||
// | ||
// Reply by the 200 OK response | ||
$psr7->respond(new Response(200, [], 'Hello RoadRunner!')); | ||
} catch (\Throwable $e) { | ||
// In case of any exceptions in the application code, you should handle | ||
// them and inform the client about the presence of a server error. | ||
// | ||
// Reply by the 500 Internal Server Error response | ||
$psr7->respond(new Response(500, [], 'Something Went Wrong!')); | ||
|
||
// Additionally, we can inform the RoadRunner that the processing | ||
// of the request failed. | ||
$psr7->getWorker()->error((string)$e); | ||
} | ||
} |