Zend Signal in PHP 5.4

Source: Internet
Author: User
Tags new features rfc sapi zend

In PHP5.4, according to the RFC submitted by Rasmus, a new signal processing mechanism is introduced to enable the signal shielding mechanism to be applied to any SAPI, and to improve PHP performance in this process.

The new mechanism, called Zend Signal, is based on Yahoo's "delayed signal processing" (Yahoo signal deferring mechanism), and then Facebook added the idea to PHP to boost Php+apache 1 . X under the PHP call Ap_block/ap_unblock performance.

Before we go into detail, I'd like to introduce the background of introducing this new mechanism:

Before I wrote two blog, introduced because the timeout signal caused by the PHP crash case: A deep understanding of PHP memory management of a low probability core analysis and a low probability of PHP core dump, in which, I said, in fact, PHP in the key operation of the time, is to set aside the signal shielding mechanism: Handle_block and unblock_interruptions. However, these two macros just hook, need to sapi their own to achieve, at present, only the Apache 1.x SAPI implementation of these two macros, that is, the use of Ap_block and Ap_unblock.

And for the scenario described in "a low probability php Core dump," if we introduce a pair of shield/unblock system calls to solve it and each time the error occurs, the performance loss will be obvious, so there is no good solution to the problem.

So Zend Signal's approach is:

1. At the start of the Zend engine, signal processing functions are registered for the following signals: SIGALRM, Sighup, SIGINT, Sigquit, Sigterm, SIGUSR1, SIGUSR2, Sigprof (under *nix), if these signals have been With the processing function, the old handler function is saved.

2. When a signal occurs, Zend_signal_handler_defer will first determine whether the current is in the block area, if not, the signal corresponding to the old processing function will be called. If so, the signal processing function is not called immediately, but waits until after Handle_unblock_interruptions, exits the block area before calling the signal processing function. If more than one signal occurs, the signal will wait in line.

3. Zend Signal use zend_signal_globals_t.depth count to determine whether the block area, Handle_block increment, handle_unblock_interruptions diminishing. When Zend _signal_globals_t.depth is greater than 0, it means that it is in block, otherwise it is not. This guarantees performance (avoiding the previous call to Sigaction to block the signal).

In addition, Zend Signal provides PHP with a new signal processing registration interface: Zend_signal.

For more detailed information, refer to [Rfc]zend singal

In the context of the introduction of Zend signal, I finally solved the problem that the timeout signal, which was the beginning of the article, could lead to crash: #60038. (Only in 5.4)

However, it is also a reminder that PHP 5.4 is still in the development phase and that any new features may be adjusted or changed before the final release. If you have any suggestions, also welcome feedback to help us make PHP better.







Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.