Skip to content

Commit 60c19fc

Browse files
committed
Apply PR laravel#932 on up-to-date branch
1 parent 4a46a6c commit 60c19fc

File tree

3 files changed

+39
-6
lines changed

3 files changed

+39
-6
lines changed

bin/checkXdebugMode.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<?php
2+
3+
exit((ini_get('xdebug.mode') ?: 'off') === 'off' ? 0 : 1);

src/Commands/StartFrankenPhpCommand.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@
1010
use Symfony\Component\Console\Command\SignalableCommandInterface;
1111
use Symfony\Component\Process\Process;
1212

13+
use function app;
14+
use function base_path;
15+
use function dirname;
16+
1317
#[AsCommand(name: 'octane:frankenphp')]
1418
class StartFrankenPhpCommand extends Command implements SignalableCommandInterface
1519
{
@@ -85,6 +89,9 @@ public function handle(ServerProcessInspector $inspector, ServerStateFile $serve
8589
? "https://$host:$port"
8690
: "http://:$port";
8791

92+
$debugEnabled = $this->debugModeEnabled($frankenphpBinary);
93+
$workerModeEnabled = $this->workerCount() == 0 && app()->environment('local') && ! $debugEnabled;
94+
8895
$process = tap(new Process([
8996
$frankenphpBinary,
9097
'run',
@@ -93,12 +100,14 @@ public function handle(ServerProcessInspector $inspector, ServerStateFile $serve
93100
'APP_ENV' => app()->environment(),
94101
'APP_BASE_PATH' => base_path(),
95102
'APP_PUBLIC_PATH' => public_path(),
103+
'APP_INDEX_FILE' => $workerModeEnabled ? 'frankenphp-worker.php' : 'index.php',
96104
'LARAVEL_OCTANE' => 1,
97105
'MAX_REQUESTS' => $this->option('max-requests'),
98106
'REQUEST_MAX_EXECUTION_TIME' => $this->maxExecutionTime(),
99107
'CADDY_GLOBAL_OPTIONS' => ($https && $this->option('http-redirect')) ? '' : 'auto_https disable_redirects',
100108
'CADDY_SERVER_ADMIN_PORT' => $this->adminPort(),
101109
'CADDY_SERVER_ADMIN_HOST' => $this->option('admin-host'),
110+
'CADDY_SERVER_FRANKENPHP_OPTIONS' => $workerModeEnabled ? 'import worker' : '',
102111
'CADDY_SERVER_LOG_LEVEL' => $this->option('log-level') ?: (app()->environment('local') ? 'INFO' : 'WARN'),
103112
'CADDY_SERVER_LOGGER' => 'json',
104113
'CADDY_SERVER_SERVER_NAME' => $serverName,
@@ -143,6 +152,23 @@ protected function ensurePortIsAvailable()
143152
}
144153
}
145154

155+
/**
156+
* Check if XDebug is installed and enabled.
157+
*
158+
* @param string $frankenPhpBinary
159+
* @return bool
160+
*/
161+
protected function debugModeEnabled($frankenPhpBinary)
162+
{
163+
$status = tap(new Process([
164+
$frankenPhpBinary,
165+
'php-cli',
166+
dirname(__DIR__, 2).'/bin/checkXdebugMode.php',
167+
], base_path()))->run();
168+
169+
return $status > 0;
170+
}
171+
146172
/**
147173
* Get the path to the FrankenPHP configuration file.
148174
*

src/Commands/stubs/Caddyfile

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
1+
(worker) {
2+
worker {
3+
file "{$APP_PUBLIC_PATH}/frankenphp-worker.php"
4+
{$CADDY_SERVER_WORKER_DIRECTIVE}
5+
{$CADDY_SERVER_WATCH_DIRECTIVES}
6+
}
7+
}
8+
19
{
210
{$CADDY_GLOBAL_OPTIONS}
311

412
admin {$CADDY_SERVER_ADMIN_HOST}:{$CADDY_SERVER_ADMIN_PORT}
513

614
frankenphp {
7-
worker {
8-
file "{$APP_PUBLIC_PATH}/frankenphp-worker.php"
9-
{$CADDY_SERVER_WORKER_DIRECTIVE}
10-
{$CADDY_SERVER_WATCH_DIRECTIVES}
11-
}
15+
{$CADDY_SERVER_FRANKENPHP_OPTIONS}
1216
}
1317
}
1418

@@ -37,7 +41,7 @@
3741
{$CADDY_SERVER_EXTRA_DIRECTIVES}
3842

3943
php_server {
40-
index frankenphp-worker.php
44+
index {$APP_INDEX_FILE}
4145
try_files {path} frankenphp-worker.php
4246
# Required for the public/storage/ directory...
4347
resolve_root_symlink

0 commit comments

Comments
 (0)