Skip to content

Commit 2e35860

Browse files
committed
add frankenphp
1 parent ec00f5c commit 2e35860

File tree

3 files changed

+79
-11
lines changed

3 files changed

+79
-11
lines changed

src/OpenApi/Frankenphp/Caddyfile

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# The Caddyfile is an easy way to configure FrankenPHP and the Caddy web server.
2+
#
3+
# https://frankenphp.dev/docs/config
4+
# https://caddyserver.com/docs/caddyfile
5+
6+
{
7+
skip_install_trust
8+
9+
auto_https disable_redirects
10+
11+
{$CADDY_GLOBAL_OPTIONS}
12+
13+
frankenphp {
14+
worker /app/vendor/astral/php-serialize/src/OpenApi/Web/index.php
15+
}
16+
}
17+
18+
{$CADDY_EXTRA_CONFIG}
19+
20+
:80 {
21+
#log {
22+
# # Redact the authorization query parameter that can be set by Mercure
23+
# format filter {
24+
# request>uri query {
25+
# replace authorization REDACTED
26+
# }
27+
# }
28+
#}
29+
30+
root vendor/astral/php-serialize/src/OpenApi/Web
31+
encode zstd br gzip
32+
33+
# Uncomment the following lines to enable Mercure and Vulcain modules
34+
#mercure {
35+
# # Transport to use (default to Bolt)
36+
# transport_url {$MERCURE_TRANSPORT_URL:bolt:///data/mercure.db}
37+
# # Publisher JWT key
38+
# publisher_jwt {env.MERCURE_PUBLISHER_JWT_KEY} {env.MERCURE_PUBLISHER_JWT_ALG}
39+
# # Subscriber JWT key
40+
# subscriber_jwt {env.MERCURE_SUBSCRIBER_JWT_KEY} {env.MERCURE_SUBSCRIBER_JWT_ALG}
41+
# # Allow anonymous subscribers (double-check that it's what you want)
42+
# anonymous
43+
# # Enable the subscription API (double-check that it's what you want)
44+
# subscriptions
45+
# # Extra directives
46+
# {$MERCURE_EXTRA_DIRECTIVES}
47+
#}
48+
#vulcain
49+
50+
{$CADDY_SERVER_EXTRA_DIRECTIVES}
51+
52+
php_server {
53+
#worker /path/to/your/worker.php
54+
}
55+
}

src/OpenApi/Frankenphp/index.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
use Astral\Serialize\OpenApi;
3+
4+
ignore_user_abort(true);
5+
require_once dirname(__DIR__, 6) . '/vendor/autoload.php';
6+
7+
$handler = static function () {
8+
try {
9+
header('Content-Type: application/json');
10+
echo (new OpenApi())->handleByFolders()->toString();
11+
} catch (JsonException|ReflectionException $e) {
12+
http_response_code(500);
13+
echo json_encode(['error' => $e->getMessage(), 'code' => $e->getCode()]);
14+
}
15+
};
16+
17+
$maxRequests = (int)($_SERVER['MAX_REQUESTS'] ?? 0);
18+
for ($nbRequests = 0; !$maxRequests || $nbRequests < $maxRequests; ++$nbRequests) {
19+
$keepRunning = frankenphp_handle_request($handler);
20+
gc_collect_cycles();
21+
if (!$keepRunning) {
22+
break;
23+
}
24+
}

src/OpenApi/Web/index.php

Lines changed: 0 additions & 11 deletions
This file was deleted.

0 commit comments

Comments
 (0)