Skip to content

Commit 172e61d

Browse files
Advance worker initialization in frankenphp-worker (#1059)
* Advance worker initialization in frankenphp-worker * Optimize debugMode * Update frankenphp-worker.php --------- Co-authored-by: Taylor Otwell <[email protected]>
1 parent f76a44e commit 172e61d

File tree

2 files changed

+8
-12
lines changed

2 files changed

+8
-12
lines changed

bin/bootstrap.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
$basePath = $_SERVER['APP_BASE_PATH'] ?? $_ENV['APP_BASE_PATH'] ?? $serverState['octaneConfig']['base_path'] ?? null;
1919

2020
if (! is_string($basePath)) {
21-
exit('Cannot find application base path.');
21+
echo 'Cannot find application base path.';
2222

2323
exit(11);
2424
}
@@ -38,7 +38,7 @@
3838
$vendorDir = $_ENV['COMPOSER_VENDOR_DIR'] ?? "{$basePath}/vendor";
3939

4040
if (! is_file($autoload_file = "{$vendorDir}/autoload.php")) {
41-
exit("Composer autoload file was not found. Did you install the project's dependencies?");
41+
echo "Composer autoload file was not found. Did you install the project's dependencies?";
4242

4343
exit(10);
4444
}

bin/frankenphp-worker.php

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,12 @@
3030

3131
$frankenPhpClient = new FrankenPhpClient();
3232

33-
$worker = null;
33+
$worker = tap(new Worker(
34+
new ApplicationFactory($basePath), $frankenPhpClient
35+
))->boot();
36+
3437
$requestCount = 0;
38+
$debugMode = $_ENV['APP_DEBUG'] ?? $_SERVER['APP_DEBUG'] ?? 'false';
3539
$maxRequests = $_ENV['MAX_REQUESTS'] ?? $_SERVER['MAX_REQUESTS'] ?? 1000;
3640
$requestMaxExecutionTime = $_ENV['REQUEST_MAX_EXECUTION_TIME'] ?? $_SERVER['REQUEST_MAX_EXECUTION_TIME'] ?? null;
3741

@@ -40,14 +44,8 @@
4044
}
4145

4246
try {
43-
$handleRequest = static function () use (&$worker, $basePath, $frankenPhpClient) {
47+
$handleRequest = static function () use ($worker, $frankenPhpClient, $debugMode) {
4448
try {
45-
$worker ??= tap(
46-
new Worker(
47-
new ApplicationFactory($basePath), $frankenPhpClient
48-
)
49-
)->boot();
50-
5149
[$request, $context] = $frankenPhpClient->marshalRequest(new RequestContext());
5250

5351
$worker->handle($request, $context);
@@ -56,8 +54,6 @@
5654
report($e);
5755
}
5856

59-
$debugMode = $_ENV['APP_DEBUG'] ?? $_SERVER['APP_DEBUG'] ?? 'false';
60-
6157
$response = new Response(
6258
$debugMode === 'true' ? (string) $e : 'Internal Server Error',
6359
500,

0 commit comments

Comments
 (0)