# RFC: Asynchronous Signal Handling

- Status: Implemented (PHP 7.1)
- Authors: Dmitry Stogov, dmitry@zend.com
- Date: 2016-06-24
- Version: 0.9
- Original: https://wiki.php.net/rfc/async_signals
- Page: https://externals.io/rfc/async_signals
- More for agents: search with https://externals.io/search.md?q={query} · RFCs at https://externals.io/rfc.md · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

## Votes

### Asynchronous Signal Handling (closed)

Yes: 21 · No: 0

Voters: 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 (closed)

pcntl.async_signals INI directive: 4 · pcntl_async_signals() function: 18

Voters: 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)

## Discussions on the mailing list

- [\[RFC\] Asynchronous Signal Handling (withiut TICKs and any additional overhead).](https://externals.io/message/94244.md) — started on 2016-06-24, 14 messages
- [\[RFC\] \[Vote\] Asynchronous Signal Handling](https://externals.io/message/94301.md) — started on 2016-06-28, 4 messages

---

## 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](https://github.com/php/php-src/pull/1953)

## Implementation

After the project is implemented, this section should contain

1. [c03ccfe78d6b13cab9546efb616a42a8f3e8a4e0](http://git.php.net/?p=php-src.git;a=commitdiff;h=c03ccfe78d6b13cab9546efb616a42a8f3e8a4e0)
2. Documentation: <http://php.net/manual/en/function.pcntl-async-signals.php>
