Skip to content

Commit 22c7002

Browse files
committed
use FrankenPHP's built-in file watcher
1 parent 253d8ae commit 22c7002

File tree

3 files changed

+42
-2
lines changed

3 files changed

+42
-2
lines changed

src/Commands/Concerns/InstallsFrankenPhpDependencies.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ trait InstallsFrankenPhpDependencies
2222
*
2323
* @var string
2424
*/
25-
protected $requiredFrankenPhpVersion = '1.1.0';
25+
protected $requiredFrankenPhpVersion = '1.3.0';
2626

2727
/**
2828
* Ensure the FrankenPHP's Caddyfile and worker script are installed.

src/Commands/StartFrankenPhpCommand.php

+36
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,9 @@ public function handle(ServerProcessInspector $inspector, ServerStateFile $serve
103103
'CADDY_SERVER_LOGGER' => 'json',
104104
'CADDY_SERVER_SERVER_NAME' => $serverName,
105105
'CADDY_SERVER_WORKER_COUNT' => $this->workerCount() ?: '',
106+
'CADDY_SERVER_WORKER_DIRECTIVE' => $this->workerCount() ? "num {$this->workerCount()}" : '',
106107
'CADDY_SERVER_EXTRA_DIRECTIVES' => $this->buildMercureConfig(),
108+
'CADDY_SERVER_WATCH_DIRECTIVES' => $this->buildWatchConfig(),
107109
]));
108110

109111
$server = $process->start();
@@ -189,6 +191,25 @@ protected function buildMercureConfig()
189191
return "$config\n\t\t}";
190192
}
191193

194+
/**
195+
* Generate the file watcher configuration snippet to include in the Caddyfile.
196+
*
197+
* @return string
198+
*/
199+
protected function buildWatchConfig()
200+
{
201+
if (! $this->option('watch')) {
202+
return '';
203+
}
204+
205+
// If paths are not specified, fall back to FrankenPHP's default watcher pattern
206+
if (empty($paths = config('octane.watch'))) {
207+
return "\t\twatch";
208+
}
209+
210+
return collect($paths)->map(fn ($path) => "\t\twatch ".base_path($path))->join("\n");
211+
}
212+
192213
/**
193214
* Get the maximum number of seconds that workers should be allowed to execute a single request.
194215
*
@@ -348,4 +369,19 @@ protected function stopServer()
348369
'--server' => 'frankenphp',
349370
]);
350371
}
372+
373+
/**
374+
* Always return a no-op object, because FrankenPHP has native
375+
* watcher support, so there is no need for an external watcher.
376+
*/
377+
protected function startServerWatcher()
378+
{
379+
return new class
380+
{
381+
public function __call($method, $parameters)
382+
{
383+
return null;
384+
}
385+
};
386+
}
351387
}

src/Commands/stubs/Caddyfile

+5-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@
44
admin {$CADDY_SERVER_ADMIN_HOST}:{$CADDY_SERVER_ADMIN_PORT}
55

66
frankenphp {
7-
worker "{$APP_PUBLIC_PATH}/frankenphp-worker.php" {$CADDY_SERVER_WORKER_COUNT}
7+
worker {
8+
file "{$APP_PUBLIC_PATH}/frankenphp-worker.php"
9+
{$CADDY_SERVER_WORKER_DIRECTIVE}
10+
{$CADDY_SERVER_WATCH_DIRECTIVES}
11+
}
812
}
913
}
1014

0 commit comments

Comments
 (0)