function Invoker::invoke
Throws
Throwable
File
-
vendor/
phpunit/ php-invoker/ src/ Invoker.php, line 28
Class
Namespace
SebastianBergmann\InvokerCode
public function invoke(callable $callable, array $arguments, int $timeout) : mixed {
if (!$this->canInvokeWithTimeout()) {
throw new ProcessControlExtensionNotLoadedException('The pcntl (process control) extension for PHP is required');
}
pcntl_signal(SIGALRM, function () : void {
throw new TimeoutException(sprintf('Execution aborted after %d second%s', $this->timeout, $this->timeout === 1 ? '' : 's'));
}, true);
$this->timeout = $timeout;
pcntl_async_signals(true);
pcntl_alarm($timeout);
try {
return call_user_func_array($callable, $arguments);
} finally {
pcntl_alarm(0);
}
}