rfc:async_signals

PHP RFC: Asynchronous Signal Handling (without TICKs)

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.

Asynchronous Signal Handling
Real name Yes No
bwoebi Image 
daverandom Image 
derick Image 
dmitry Image 
gasolwu Image 
guilhermeblanco Image 
hywan Image 
jhdxr Image 
jpauli Image 
kguest Image 
kinncj Image 
lbarnaud Image 
lcobucci Image 
marcio Image 
mariano Image 
mbeccati Image 
mrook Image 
ocramius Image 
santiagolizardo Image 
trowski Image 
zimt Image 
Final result: 21 0
This poll has been closed.

An additional 1/2 majority question:

Chose between old and new behavior in PHP 7.* using
Real name pcntl.async_signals INI directive pcntl_async_signals() function
bwoebi  Image
danack  Image
daverandom  Image
derick  Image
dmitry Image 
gasolwu Image 
guilhermeblanco  Image
hywan  Image
jhdxr Image 
jpauli  Image
kguest  Image
kinncj  Image
lbarnaud  Image
lcobucci  Image
levim  Image
marcio  Image
mariano  Image
mbeccati  Image
mrook  Image
ocramius  Image
trowski  Image
zimt Image 
Final result: 4 18
This poll has been closed.

Patches and Tests

The patch is really simple: PR 1953

Implementation

After the project is implemented, this section should contain

rfc/async_signals.txt · Last modified: by 127.0.0.1

Image