Both sides previous revisionPrevious revisionNext revision | Previous revision |
rfc:additional-context-in-pcntl-signal-handler [2016/06/20 15:05] – Clarified behavior on systems with siginfo_t. Added more documentation on use cases and available fields. bishop | rfc:additional-context-in-pcntl-signal-handler [2017/09/22 13:28] (current) – external edit 127.0.0.1 |
---|
====== PHP RFC: Additional Context in pcntl_signal Handler ====== | ====== PHP RFC: Additional Context in pcntl_signal Handler ====== |
* Version: 0.2 | * Version: 1.0 |
* Date: 2016-06-14 | * Date: 2016-06-14 |
* Author: David Walker <dave@mudsite.com>, Bishop Bettini <bishop@php.net> | * Authors: David Walker <dave@mudsite.com>, Bishop Bettini <bishop@php.net> |
* Status: Draft | * Status: Accepted |
* First Published at: http://wiki.php.net/rfc/additional-context-in-pcntl-signal-handler | * First Published at: http://wiki.php.net/rfc/additional-context-in-pcntl-signal-handler |
| |
printf('USR1 from %s', $siginfo['pid'] ?? 'unknown'); | printf('USR1 from %s', $siginfo['pid'] ?? 'unknown'); |
}); | }); |
posix_kill(0, SIGUSR1); | posix_kill(posix_getpid(), SIGUSR1); |
| pcntl_signal_dispatch(); |
</file> | </file> |
| |
* **''mtime''**, the time of last data modification, if appropriate for the signal. | * **''mtime''**, the time of last data modification, if appropriate for the signal. |
| |
Like other ''pcntl'' functions that map internal ''signal.h'' names into PHP keys, the leading ''si_'' has been removed. (That is, in the C documentation "''si_signo''" becomes "''signo''" in PHP.) However, this does not apply to the values of the ''code'' field, as those represent system-specific constants that follow no normative naming convention. | The naming of ''$siginfo'' and its keys comes from the ''pcntl_sigwaitinfo'' implementation. (So for example, "''signo''" in PHP comes from "''si_signo''" in the C structure, the leading "si_" having been removed by the PHP engine.) Name normalization does not apply to the values of the ''code'' field, as those represent system-specific values that follow no normative naming convention. |
| |
Some older systems not conforming to [[https://standards.ieee.org/findstds/standard/1003.1-2001.html|POSIX.1-2001]] (where this structure was formally codified) may not support passing the additional context. In such case, PHP will pass ''null'' as the second argument to the handler. | Some older systems not conforming to [[https://standards.ieee.org/findstds/standard/1003.1-2001.html|POSIX.1-2001]] (where this structure was formally codified) may not support passing the additional context. In such case, PHP will pass ''null'' as the second argument to the handler. |
===== Proposed PHP Version(s) ===== | ===== Proposed PHP Version(s) ===== |
| |
Next PHP 7.x. | Next PHP 7.x, currently 7.1. |
| |
| |
None. | None. |
| |
| ===== Discussion ===== |
| |
| Instead of updating ''pcntl_signal'', it was suggested to add a method ''pcntl_sigaction'', which would "keep maximum compatibility and eliminate unnecessary additional overhead". This suggestion was later withdrawn as perhaps adding more complication than the patch itself, though a later [[https://github.com/php/php-src/pull/1985|PR]] addressed parts of the suggestion. [[https://www.mail-archive.com/internals@lists.php.net/msg86504.html|Reference.]] |
| |
| Performance was raised as a concern. Having run tests through callgrind there is an additional 0.0001% cost for the feature. The profiled code defined an empty function, set the handler, and triggered the signal. Passing the additional information resulted in 2000 extra instructions, out of a total 13 million. This seems negligible compared to the cost of acquiring the same information through other means (eg message queues, temporary files, etc.). |
| |
===== Open Issues ===== | ===== Open Issues ===== |
Requires a 50%+1 majority. | Requires a 50%+1 majority. |
| |
| <doodle title="Provide additional context in pcntl signal handler?" auth="bishopb" voteType="single" closed="true"> |
| * Yes |
| * No |
| </doodle> |
| |
| Voting shall close one week after opening on Thursday, July 14, 2016 at 23:59 UTC. |
| |
===== Patches and Tests ===== | ===== Patches and Tests ===== |
| |
* [[https://github.com/bp1222/php-src|Work in Progress]] | * [[https://github.com/php/php-src/pull/1993|Implementation with tests.]] |
| |
| |
| |
* [[https://marc.info/?l=php-internals&m=146584196929126&w=2|Initial ping to php.internals]] | * [[https://marc.info/?l=php-internals&m=146584196929126&w=2|Initial ping to php.internals]] |
| * [[https://marc.info/?l=php-internals&m=146670242109688&w=2|Discussion]] |