dmitry

Dmitry Stogov , from Zend Technologies
(user votes do not necessarily reflect their company's views)

Contents

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.

Patches and Tests

The patch is really simple: PR 1953

Implementation

After the project is implemented, this section should contain

Votes

An option needs 2/3 votes to win

Asynchronous Signal Handling (100% approved)
User Vote
bwoebi Yes
daverandom Yes
derick Yes
dmitry Yes
gasolwu Yes
guilhermeblanco Yes
hywan Yes
jhdxr Yes
jpauli Yes
kguest Yes
kinncj Yes
lbarnaud Yes
lcobucci Yes
marcio Yes
mariano Yes
mbeccati Yes
mrook Yes
ocramius Yes
santiagolizardo Yes
trowski Yes
zimt Yes
Chose between old and new behavior in PHP 7.* using (100% approved)
User Vote
bwoebi Pcntl_async_signals() function
danack Pcntl_async_signals() function
daverandom Pcntl_async_signals() function
derick Pcntl_async_signals() function
dmitry Pcntl.async_signals INI directive
gasolwu Pcntl.async_signals INI directive
guilhermeblanco Pcntl_async_signals() function
hywan Pcntl_async_signals() function
jhdxr Pcntl.async_signals INI directive
jpauli Pcntl_async_signals() function
kguest Pcntl_async_signals() function
kinncj Pcntl_async_signals() function
lbarnaud Pcntl_async_signals() function
lcobucci Pcntl_async_signals() function
levim Pcntl_async_signals() function
marcio Pcntl_async_signals() function
mariano Pcntl_async_signals() function
mbeccati Pcntl_async_signals() function
mrook Pcntl_async_signals() function
ocramius Pcntl_async_signals() function
trowski Pcntl_async_signals() function
zimt Pcntl.async_signals INI directive