manually control timeout, to dump trace data after hitting the limit

This commit is contained in:
Shish
2023-06-25 13:39:03 +01:00
parent 1d4c43f33b
commit b85e7ec209
10 changed files with 47 additions and 11 deletions

32
core/timeout.php Normal file
View File

@@ -0,0 +1,32 @@
<?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();
}
}
}