Skip to content

Commit 00e4d40

Browse files
Use FrankenPHP's built-in file watcher (#971)
* use FrankenPHP's built-in file watcher * Update StartFrankenPhpCommand.php --------- Co-authored-by: Taylor Otwell <[email protected]>
1 parent fe9b236 commit 00e4d40

File tree

3 files changed

+43
-2
lines changed

3 files changed

+43
-2
lines changed

src/Commands/Concerns/InstallsFrankenPhpDependencies.php

Lines changed: 1 addition & 1 deletion
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

Lines changed: 37 additions & 0 deletions
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,41 @@ protected function buildMercureConfig()
189191
return "$config\n\t\t}";
190192
}
191193

194+
/**
195+
* Always return a no-op object, because FrankenPHP has native watcher support.
196+
*
197+
* @return object
198+
*/
199+
protected function startServerWatcher()
200+
{
201+
return new class
202+
{
203+
public function __call($method, $parameters)
204+
{
205+
return null;
206+
}
207+
};
208+
}
209+
210+
/**
211+
* Generate the file watcher configuration snippet to include in the Caddyfile.
212+
*
213+
* @return string
214+
*/
215+
protected function buildWatchConfig()
216+
{
217+
if (! $this->option('watch')) {
218+
return '';
219+
}
220+
221+
// If paths are not specified, fall back to FrankenPHP's default watcher pattern...
222+
if (empty($paths = config('octane.watch'))) {
223+
return "\t\twatch";
224+
}
225+
226+
return collect($paths)->map(fn ($path) => "\t\twatch ".base_path($path))->join("\n");
227+
}
228+
192229
/**
193230
* Get the maximum number of seconds that workers should be allowed to execute a single request.
194231
*

src/Commands/stubs/Caddyfile

Lines changed: 5 additions & 1 deletion
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)