/usr/share/php/PHP/Invoker/Invoker.php is in php-invoker 1.1.4-3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 | <?php
/*
* This file is part of the PHP_Invoker package.
*
* (c) Sebastian Bergmann <sebastian@phpunit.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
declare(ticks = 1);
/**
* Utility class for invoking callables with a timeout.
*
* @since Class available since Release 1.0.0
*/
class PHP_Invoker
{
/**
* @var int
*/
protected $timeout;
/**
* Invokes a callable and raises an exception when the execution does not
* finish before the specified timeout.
*
* @param callable $callable
* @param array $arguments
* @param int $timeout in seconds
* @return mixed
* @throws InvalidArgumentException
*/
public function invoke($callable, array $arguments, $timeout)
{
if (!is_callable($callable)) {
throw new InvalidArgumentException;
}
if (!is_integer($timeout)) {
throw new InvalidArgumentException;
}
pcntl_signal(SIGALRM, array($this, 'callback'), TRUE);
pcntl_alarm($timeout);
$this->timeout = $timeout;
try {
$result = call_user_func_array($callable, $arguments);
}
catch (Exception $e) {
pcntl_alarm(0);
throw $e;
}
pcntl_alarm(0);
return $result;
}
/**
* Invoked by pcntl_signal() when a SIGALRM occurs.
*/
public function callback()
{
throw new PHP_Invoker_TimeoutException(
sprintf(
'Execution aborted after %s',
PHP_Timer::secondsToTimeString($this->timeout)
)
);
}
}
|