Take the State of PHP 2026 Survey →

Asynchronous Signal Handling View as Markdown

Implemented (PHP 7.1)
Authors
Dmitry Stogov, dmitry@zend.com
Date
2016-06-24
Version
0.9
Source
wiki.php.net/rfc/async_signals

Votes

Asynchronous Signal Handling closed
Yes
21
No
0
21 voters
bwoebi Yes 2016-06-28 17:30
daverandom Yes 2016-06-29 17:14
derick Yes 2016-06-29 14:18
dmitry Yes 2016-06-28 16:12
gasolwu Yes 2016-07-04 04:41
guilhermeblanco Yes 2016-07-04 03:11
hywan Yes 2016-06-29 12:39
jhdxr Yes 2016-07-06 04:27
jpauli Yes 2016-06-29 09:03
kguest Yes 2016-06-29 15:21
kinncj Yes 2016-06-29 16:10
lbarnaud Yes 2016-06-29 14:52
lcobucci Yes 2016-07-04 23:12
marcio Yes 2016-07-04 00:57
mariano Yes 2016-06-28 21:33
mbeccati Yes 2016-06-30 12:39
mrook Yes 2016-07-05 07:51
ocramius Yes 2016-07-03 03:29
santiagolizardo Yes 2016-06-29 22:07
trowski Yes 2016-06-28 18:14
zimt Yes 2016-06-29 08:19
Chose between old and new behavior in PHP 7.* using closed
pcntl.async_signals INI directive
4
pcntl_async_signals() function
18
22 voters
bwoebi pcntl_async_signals() function 2016-06-29 10:04
danack pcntl_async_signals() function 2016-06-28 23:38
daverandom pcntl_async_signals() function 2016-06-29 17:14
derick pcntl_async_signals() function 2016-06-29 14:18
dmitry pcntl.async_signals INI directive 2016-06-28 16:12
gasolwu pcntl.async_signals INI directive 2016-07-04 04:44
guilhermeblanco pcntl_async_signals() function 2016-07-04 03:12
hywan pcntl_async_signals() function 2016-06-29 12:39
jhdxr pcntl.async_signals INI directive 2016-07-06 04:27
jpauli pcntl_async_signals() function 2016-06-29 09:03
kguest pcntl_async_signals() function 2016-06-29 15:22
kinncj pcntl_async_signals() function 2016-06-29 16:11
lbarnaud pcntl_async_signals() function 2016-06-29 14:52
lcobucci pcntl_async_signals() function 2016-07-04 23:12
levim pcntl_async_signals() function 2016-06-29 16:11
marcio pcntl_async_signals() function 2016-07-04 00:58
mariano pcntl_async_signals() function 2016-06-30 16:06
mbeccati pcntl_async_signals() function 2016-06-30 12:39
mrook pcntl_async_signals() function 2016-07-05 07:51
ocramius pcntl_async_signals() function 2016-07-03 03:29
trowski pcntl_async_signals() function 2016-06-28 18:14
zimt pcntl.async_signals INI directive 2016-06-29 08:19

Discussions on the mailing list

[RFC] [Vote] Asynchronous Signal Handling
by Dmitry Stogov · 4 messages

RFC text

Copied from wiki.php.net, last synchronized Oct 13, 2026 11:51 UTC

Introduction

Currently php may handle OS signals using pcntl extensions:

  • synchronously, calling pcntl_signal_dispatch() manually
  • asynchronously, compiling scripts with declare(ticks=1)

However, TICKs introduce huge overhead.

Proposal

Zend Engine in PHP 7.1 was extended with ability of safe time-out and interrupt handling. Actually, PHP VM checks for EG(vm_interrupt) flag on each loop iteration, user function entry or internal function exit, and call callback function if necessary.

I propose to use this ability to implement asynchronous signal handling. Registered signal handlers are going to be called at some points during user script execution without any overhead.

To keep ability of synchronous signal, handling we had to introduce a new INI directive pcntl.async_signals with default value 0. Bob pointed, that instead of INI directive, we may use function pcntl_async_signals(bool on_off). In my opinion, this doesn't make a big difference. In first case, some PHP script may don't know the value set through php.ini. In the second, it may don't know the previous value set through pcntl_async_signals().

Backward Incompatible Changes

None

Proposed PHP Version(s)

PHP 7.1

RFC Impact

php.ini Defaults

  • pcntl.async_signals=0, it's value may be changed at run-time through ini_set().

Future Scope

In the next major PHP version we may remove ability of manual signal handling and corresponding pcntl.async_signals INI directive or pcntl_async_signals() function.

Proposed Voting Choices

The vote is a straight Yes/No vote, that requires a 2/3 majority. The vote began on June 28 and will finish on July 6.

Vote: Asynchronous Signal Handling — Yes: 21 · No: 0 (closed)

An additional 1/2 majority question:

Vote: Chose between old and new behavior in PHP 7.* using — pcntl.async_signals INI directive: 4 · pcntl_async_signals() function: 18 (closed)

Patches and Tests

The patch is really simple: PR 1953

Implementation

After the project is implemented, this section should contain

  1. c03ccfe78d6b13cab9546efb616a42a8f3e8a4e0
  2. Documentation: http://php.net/manual/en/function.pcntl-async-signals.php