Skip to content
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Added check for XDebug mode as an additional requirement to enable Fr…
…ankenPHP worker mode to avoid performance issues.

See the discussion with Kévin Dunglas in the PR discussion for the reasoning: #932

Essentially, disabling worker mode comes with performance drawbacks, but it's still the only sensible way to use FrankenPHP with XDebug.
By automatically turning off worker mode if
 a) the amount of workers isn't set explicitly,
 b) we're running locally, and
 c) XDebug is not installed, or it's mode is set to "off",
we get both optimal performance and XDebug working out of the box.
  • Loading branch information
Radiergummi committed Sep 6, 2024
commit 4944d1d397bdf231b68400b660b207bcc2509631
3 changes: 3 additions & 0 deletions bin/checkXdebugMode.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?php

exit((ini_get('xdebug.mode') ?: 'off') === 'off' ? 0 : 1);
29 changes: 27 additions & 2 deletions src/Commands/StartFrankenPhpCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
use Symfony\Component\Console\Command\SignalableCommandInterface;
use Symfony\Component\Process\Process;

use function app;
use function base_path;
use function dirname;

#[AsCommand(name: 'octane:frankenphp')]
class StartFrankenPhpCommand extends Command implements SignalableCommandInterface
{
Expand Down Expand Up @@ -85,6 +89,9 @@ public function handle(ServerProcessInspector $inspector, ServerStateFile $serve
? "https://$host:$port"
: "http://:$port";

$debugEnabled = $this->debugModeEnabled($frankenphpBinary);
$workerModeEnabled = $this->workerCount() == 0 && app()->environment('local') && ! $debugEnabled;

$process = tap(new Process([
$frankenphpBinary,
'run',
Expand All @@ -93,14 +100,14 @@ public function handle(ServerProcessInspector $inspector, ServerStateFile $serve
'APP_ENV' => app()->environment(),
'APP_BASE_PATH' => base_path(),
'APP_PUBLIC_PATH' => public_path(),
'APP_INDEX_FILE' => $this->workerCount() == 0 && app()->environment('local') ? 'index.php' : 'frankenphp-worker.php',
'APP_INDEX_FILE' => $workerModeEnabled ? 'frankenphp-worker.php' : 'index.php',
'LARAVEL_OCTANE' => 1,
'MAX_REQUESTS' => $this->option('max-requests'),
'REQUEST_MAX_EXECUTION_TIME' => $this->maxExecutionTime(),
'CADDY_GLOBAL_OPTIONS' => ($https && $this->option('http-redirect')) ? '' : 'auto_https disable_redirects',
'CADDY_SERVER_ADMIN_PORT' => $this->adminPort(),
'CADDY_SERVER_ADMIN_HOST' => $this->option('admin-host'),
'CADDY_SERVER_FRANKENPHP_OPTIONS' => $this->workerCount() == 0 && app()->environment('local') ? '' : 'import worker',
'CADDY_SERVER_FRANKENPHP_OPTIONS' => $workerModeEnabled ? 'import worker' : '',
'CADDY_SERVER_LOG_LEVEL' => $this->option('log-level') ?: (app()->environment('local') ? 'INFO' : 'WARN'),
'CADDY_SERVER_LOGGER' => 'json',
'CADDY_SERVER_SERVER_NAME' => $serverName,
Expand Down Expand Up @@ -143,6 +150,24 @@ protected function ensurePortIsAvailable()
}
}

/**
* Check if XDebug is installed and enabled.
*
* @param string $frankenPhpBinary
*
* @return bool
*/
protected function debugModeEnabled($frankenPhpBinary)
{
$status = tap(new Process([
$frankenPhpBinary,
'php-cli',
dirname(__DIR__, 2).'/bin/checkXdebugMode.php',
], base_path()))->run();

return $status > 0;
}

/**
* Get the path to the FrankenPHP configuration file.
*
Expand Down