Hello Internals,

PHP suffers from several issues related to timeout and signal handling,
especially when built with ZTS enabled.

1. The current implementation of timeouts on UNIX builds seems
"fundamentally incompatible with ZTS" (
https://bugs.php.net/bug.php?id=79464#1589205685) and more anecdotally
conflicts with some Go features (
https://github.com/golang/go/issues/56260#issuecomment-1281040802)
2. "Zend Signals" causes segmentation faults and other problems in
multi-threaded environments (
https://github.com/php/php-src/issues/9649#issuecomment-1264330874,
https://github.com/php/php-src/pull/5591#issuecomment-650064098), and seems
useless anyway since PHP 7.1 (
https://github.com/php/php-src/pull/5591#issuecomment-645428002)

In 2020, Alex Dowad started a major refactoring to improve these parts (
https://github.com/php/php-src/pull/5570,
https://github.com/php/php-src/pull/5591,
https://github.com/php/php-src/pull/5710), but he stopped working on it.

Instead of doing a major one-time refactoring like that, I propose moving
forward little by little to limit the risks and the potential backward
compatibility breaks.

Here is the plan:

1. Switch to timer_create() for timeouts, but only on Linux (it's not
supported on other platforms yet), when ZTS is enabled and Zend Signals is
disabled. As the feature is currently entirely broken when ZTS is on, this
can be considered a bug fix and cannot be worse than it currently is.
1bis. Can be done independently of 1., and even in parallel, optional as
long as we keep the --disable-zend-signals flag: Remove Zend Signals
entirely, because even if it can be partially fixed (I proposed a patch
fixing segfaults: https://github.com/php/php-src/pull/9766), it seems now
useless and causes unfixable issues with some signals such as SIGINT (
https://github.com/php/php-src/issues/9649#issuecomment-1265811930)
2. Switch to Grand Central Dispatch on macOS and FreeBSD when ZTS is
enabled and Zend Signals is disabled (if not removed at this point), which
provides a feature similar to timer_create() for these platforms.
3. Probably in a future major version, optional: switch to
timer_create()/GCD even for non-ZTS builds to uniformize and simplify the
code.

What do you think about this plan? Apart from the technical aspects, what's
the best way forward? Submit patches? Propose an RFC? Do both? (pardon my
ignorance of internals processes).

Thank you,
-- 
Kévin Dunglas

Reply via email to