Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
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
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);
26 changes: 26 additions & 0 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,12 +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' => $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' => $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 @@ -141,6 +150,23 @@ 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
8 changes: 6 additions & 2 deletions src/Commands/stubs/Caddyfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
(worker) {
worker "{$APP_PUBLIC_PATH}/frankenphp-worker.php" {$CADDY_SERVER_WORKER_COUNT}
}

{
{$CADDY_GLOBAL_OPTIONS}

admin {$CADDY_SERVER_ADMIN_HOST}:{$CADDY_SERVER_ADMIN_PORT}

frankenphp {
worker "{$APP_PUBLIC_PATH}/frankenphp-worker.php" {$CADDY_SERVER_WORKER_COUNT}
{$CADDY_SERVER_FRANKENPHP_OPTIONS}
}
}

Expand All @@ -31,7 +35,7 @@
{$CADDY_SERVER_EXTRA_DIRECTIVES}

php_server {
index frankenphp-worker.php
index {$APP_INDEX_FILE}
# Required for the public/storage/ directory...
resolve_root_symlink
}
Expand Down