Process scan isolators for PHP 8.4.
Packagist package and source repository: super-kernel/scan-isolate.
This package provides a small ScanIsolatorInterface for scan work that may need to run in an isolated process while
keeping the public result model minimal.
- explicit scan isolator contract
- lightweight
ScannedInterfaceresult NullScanIsolatorfor already-isolated PHAR runtimesPcntlScanIsolatorfor fork-based isolationProcScanIsolatorfor self-bootstrap isolation throughproc_open()- stdout and stderr forwarding in proc mode
- no custom worker entry script
- PHP
~8.4.0 ext-jsonext-pcntlforPcntlScanIsolator- CLI and
proc_open()forProcScanIsolator
composer require super-kernel/scan-isolateuse SuperKernel\ScanIsolate\Executor\ProcScanIsolator;
$isolator = new ProcScanIsolator();
if (!$isolator->supports()) {
throw new RuntimeException('Proc scan isolation is not available.');
}
$scanned = $isolator->execute(static function (): void {
// scan logic runs in the isolated child process
});
assert($scanned->isScanned());
// current process continues only after the isolated scan completed successfullynamespace SuperKernel\ScanIsolate\Contract;
interface ScanIsolatorInterface
{
public function supports(): bool;
public function execute(callable $callback): ScannedInterface;
}ScannedInterface::isScanned() tells you whether the scan workflow has completed successfully for the current call.
true: the scan was completed successfullyfalse: the scan has not been completed
| Isolator | Best fit | Child execution model | Parent return |
|---|---|---|---|
NullScanIsolator |
Already running inside a PHAR-isolated context | no extra process | Scanned(true) |
PcntlScanIsolator |
CLI runtime with ext-pcntl available |
pcntl_fork() |
Scanned(true) |
ProcScanIsolator |
CLI runtime where self-bootstrap via current entrypoint is acceptable | proc_open() + current $_SERVER['SCRIPT_FILENAME'] |
Scanned(true) |
Returns new Scanned(true) immediately.
Use it when the current runtime is already isolated, and you only want a consistent ScanIsolatorInterface.
Uses pcntl_fork() and pcntl_waitpid().
- child process executes the callback and exits immediately
- parent process waits for child completion and returns
Scanned(true) - non-zero child exit raises
ScanIsolatorException
Starts a new PHP process with PHP_BINARY and the current $_SERVER['SCRIPT_FILENAME'].
The child process must reach the same execute() call naturally. There is no separate worker entry file.
- child process consumes the guard descriptor
- child process executes the callback
- child process writes a scan result token back to the parent
- child process exits immediately after the callback succeeds
- parent process forwards child stdout and stderr to the current output
- parent process returns
Scanned(true)after the child exits successfully
If the current entry script does not reach the scan point, or if the child exits non-zero, ScanIsolatorException is
thrown.
use SuperKernel\ScanIsolate\Executor\PcntlScanIsolator;
$isolator = new PcntlScanIsolator();
$scanned = $isolator->execute(static function (): void {
// scan in the forked child process
});
assert($scanned->isScanned());
// current process continues only after the child scan completed successfullyuse SuperKernel\ScanIsolate\Executor\ProcScanIsolator;
$isolator = new ProcScanIsolator();
$scanned = $isolator->execute(static function (): void {
// scan in the self-bootstrapped child process
});
assert($scanned->isScanned());
// current process continues only after the child scan completed successfullysupports()is a capability check, not a guarantee thatexecute()cannot fail at runtime.- child processes do not return to the caller after a successful callback; they terminate.
- callback failures are surfaced as
ScanIsolatorExceptionin the parent process. ProcScanIsolatoris designed for re-entering the current application entrypoint, not for launching a custom worker script.
php84 vendor/bin/phpunit