This repository has been archived on 2024-09-05. You can view files and clone it, but cannot push or open issues or pull requests.
shimmie2/core/timeout.php
2023-06-25 14:04:26 +01:00

32 lines
567 B
PHP

<?php
class TimeoutException extends RuntimeException
{
}
class Timeout
{
private $active;
public function set($seconds)
{
$this->active = true;
// declare(ticks = 1);
// pcntl_signal(SIGALRM, [$this, 'handle'], true);
// pcntl_alarm($seconds);
set_time_limit($seconds + 5);
}
public function clear()
{
set_time_limit(0);
$this->active = false;
}
public function handle($signal)
{
if ($this->active) {
throw new TimeoutException();
}
}
}