rfc:zendsignals

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
rfc:zendsignals [2008/07/06 09:41] – Some cleanup and add more performance detail. lucasrfc:zendsignals [2017/09/22 13:28] (current) – external edit 127.0.0.1
Line 3: Line 3:
   * Date: 2008-07-05   * Date: 2008-07-05
   * Author: Lucas Nealan <lucas@facebook.com>   * Author: Lucas Nealan <lucas@facebook.com>
-  * Status: Under Discussion+  * Status: Implemented in PHP 5.4
   * First Proposed by: [[http://markmail.org/message/3jg6cwqfghdlydhy|Rasmus Lerdorf]]   * First Proposed by: [[http://markmail.org/message/3jg6cwqfghdlydhy|Rasmus Lerdorf]]
-  * Source code: [[http://sizzo.org/~screen/patches/php-5.3.0-alarms-0807051839.patch|PHP_5_3_0 patch]].+  * Source code: [[http://tekrat.com/downloads/bits/php-5.3-signals.20091120.patch|PHP_5_3 patch]] [[http://tekrat.com/downloads/bits/php-trunk-signals.20091120.patch|PHP Trunk patch]] (11-20-2009).
  
 ===== Introduction ===== ===== Introduction =====
Line 85: Line 85:
 ===== Considerations ===== ===== Considerations =====
  
-  - Zend Signal Handling support has not been implemented for ZTS enabled php builds. While this is likely to improve PHP stability under Apache 2 using the prefork MPM, there will be no such improvement under the worker MPM.+  - Limited Zend Signal Handling support has been implemented for ZTS enabled php builds. Future development is planned to add support for ZTS windows builds.
  
-  - The current implementation is not enabled by default, to enable pass --enable-zend-signals to PHP configure. 
-  
-  - The proposal has only been implemented for PHP_5_3 and will need to be ported to PHP 6. 
-  
   - For simplicity the //_zend_signal_info_t.prev// structure is implemented as a static vector of NSIG size. On some systems NSIG may not be defined and 65 will be used as the default vector size.   - For simplicity the //_zend_signal_info_t.prev// structure is implemented as a static vector of NSIG size. On some systems NSIG may not be defined and 65 will be used as the default vector size.
 +
 +  - A signal queue of ZEND_SIGNAL_QUEUE_SIZE is created to handle recieved signals within critical sections. It is initialized to support 32 signals. If more are received after this they are discarded.
 +
 +===== Discoveries =====
 +=== pcntl extension signals ===
 +The pcntl extension allows signal handlers to be defined in PHP userspace via //[[http://docs.php.net/manual/en/function.pcntl-signal.php|pctnl_signal()]]//. The handler is installed via //signal// and any previously registered handlers for the specified signal are ignored. While this is technically incompatible with Zend Signals, if a handler is installed via //pctnl_signal// for signals SIGALRM, SIGHUP, SIGINT, SIGQUIT, SIGTERM, SIGUSR1, SIGUSR2, the deferred protection offered by Zend Signals will basically be disabled for that signal number.
 +
 +Note: Although --enable-pcntl states "(CLI/CGI only)" in the config.m4, there is no actual enforcement of this at compile time. The extension can be running in any SAPI.
 +
 +Update: pcntl has been modified to register signals via //zend_signal()// when available. Critical sections will now continue to have deferred protection even after signals are registered via pcntl.
 +
 +=== PHP SIGCHLD signal handler ===
 +To deal with zombied or defunct children SIGCHILD handling was added to PHP via --enable-sigchild. This is apparently very common during disconnect when using oracle libraries to connect via the BEQ interface. When enabled, a handler for SIGCHILD is installed during php_startup. This handler calls //waitpid()// for any children assuring that their exit status is read and the zombies will not remain until php exits. 
 +
 +Since Zend Signals does not install a handler for SIGCHILD there is no explicit conflict. Also the simplicity of the handler should ensure that it does not adversely affect any critical zend sections. In future versions we may want to bring this functionality into Zend and enable by default on all platforms that support SIGCHLD ass well as implement via //sigaction()//.
 +
 +Note: When calling //wait()// or //waitpid()// within a handler the global errno may be modified. I have modified the existing handler in this patch to account for this. 
  
 ===== Changelog ===== ===== Changelog =====
  
-   - 2008-07-05 Lucas Nealan: Initial creation+   - 2008-07-05 Lucas Nealan: Initial creation ([[http://markmail.org/thread/di2fr6vzovagqofc|Discussed on internals]]) 
 +   - 2008-07-08 Lucas Nealan: Updated patch for php_request_shutdown order issue ([[http://sizzo.org/~screen/patches/php-5.3.0-alarms-0807051839.patch|prev patch]]) 
 +   - 2008-07-29 Lucas Nealan: Update patch to fix reentrance in handler, enable by default, stolen signal reporting ([[http://sizzo.org/~screen/patches/php-5.3.0-alarms-0807081632.patch|prev patch]]) 
 +   - 2008-08-01 Lucas Nealan: Update patch to fix tests, alloc/free on php startup/shutdown, ini for shutdown tests ([[http://sizzo.org/~screen/patches/php-5.3.0-alarms-0807291627.patch|prev patch]]) 
 +   - 2008-08-03 Lucas Nealan: Incorporated ZTS support by Arnaud Le Blanc, moved ini def to zend.c, added HEAD patch ([[http://sizzo.org/~screen/patches/php-5.3.0-alarms-0808010408.patch|prev patch]]) 
 +   - 2008-08-05 Arnaud Le Blanc: Added zend_sigaction() and ported PCNTL to use it. ([[http://sizzo.org/~screen/patches/php-5.3.0-alarms-0808021704.patch|PHP_5_3_0 prev patch]] [[http://sizzo.org/~screen/patches/php-HEAD-alarms-0808021832.patch|PHP_HEAD prev patch]]) 
 +   - 2008-08-12 Lucas Nealan: Update patches to latest CVS, minor TWS fixes etc. ([[http://arnaud.lb.s3.amazonaws.com/php-5.3.0-alarms-0808051122.patch|PHP_5_3_0 prev patc]] [[http://arnaud.lb.s3.amazonaws.com/php-HEAD-alarms-0808051122.patch|PHP_HEAD prev patch]]) 
 +   - 2009-11-20 Brian Shire: Updated patches for latest CVS with some fixes for bugs caused by another fix to the handling of signals during user-space shutdown functions. ([[http://sizzo.org/~screen/patches/php-5.3.0-alarms-0808121020.patch|PHP_5_3_0 prev patch]] [[http://sizzo.org/~screen/patches/php-HEAD-alarms-0808121015.patch|PHP_HEAD prev patch]])
rfc/zendsignals.1215337289.txt.gz · Last modified: 2017/09/22 13:28 (external edit)