Skip to content

Commit c9c18cc

Browse files
This function is now standard in php
1 parent 33f6264 commit c9c18cc

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

classes/util/PcntlTimeout.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,9 @@ public function __construct(int $timeout)
5858
*/
5959
public function timeBoxed(callable $code)
6060
{
61-
$signal = pcntl_signal(SIGALRM, function () {
61+
$existingHandler = pcntl_signal_get_handler(SIGALRM);
62+
63+
$signal = pcntl_signal(SIGALRM, function (): void {
6264
throw new DeadlineException(sprintf("Timebox hit deadline of %d seconds", $this->timeout));
6365
});
6466
if (!$signal) {
@@ -73,7 +75,7 @@ public function timeBoxed(callable $code)
7375
} finally {
7476
pcntl_alarm(0);
7577
pcntl_signal_dispatch();
76-
pcntl_signal(SIGALRM, SIG_DFL);
78+
pcntl_signal(SIGALRM, $existingHandler);
7779
}
7880
}
7981

0 commit comments

Comments
 (0)