pcntl_alarm(int $seconds) only has a resolution of seconds. Is there a way in PHP to signal a SIGALRM with a delay of, say, milliseconds? Maybe a posix_kill() with a delay argument?
PS.: I'm aware of Swoole\Process::alarm() from the PECL extension Swoole, but I'm looking for a more bare-bones PHP solution.
I found one way to do it, but it is a bit convoluted:
...and it's way too resource intensive. And because it needs to spawn a new process each time probably not very time-accurate either.
Addendum:
I've managed to make it more efficient by creating only one long-running interrupter process, instead of creating short-running processes for each interruption request.
It's still far from ideal, but it does the job for now: