You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Adds FrankenPHP\ShutdownException to gracefully interrupt background
workers blocked in C-level calls (sleep, Redis subscribe, etc.).
On POSIX, pthread_kill(SIGUSR1) interrupts the blocked syscall with
EINTR. The signal handler sets EG(vm_interrupt), causing the Zend VM
to throw ShutdownException at the next opcode boundary.
On Windows, CancelSynchronousIo() interrupts blocked I/O and the
shutdown flag triggers the same exception path.
PHP code catches it with try/catch - no new API, no callback:
try {
$redis->subscribe([...], function ($msg) { ... });
} catch (\FrankenPHP\ShutdownException) {
return Command::SUCCESS;
}
Returns a readable stream used for receiving signals from FrankenPHP.
89
-
Signals are newline-terminated strings: `"stop\n"` signals shutdown or restart.
90
-
Read with `fgets()` to identify the signal type.
88
+
When FrankenPHP needs to stop a background worker (server shutdown, worker restart, file watcher trigger), it throws a `FrankenPHP\ShutdownException`. This exception interrupts any blocking PHP call - `sleep()`, `stream_select()`, Redis `subscribe()`, etc.
91
89
92
-
Use `stream_select()` instead of `sleep()` or `usleep()`to wait between iterations:
90
+
Use `try/catch`to handle shutdown gracefully:
93
91
94
92
```php
95
-
function background_worker_should_stop(float $timeout = 0): bool
0 commit comments