Troubleshooting of a strange exit of a php process

Source: Internet
Author: User
Background recently, an anti-spam platform was set up for XX Project. The results were good, but there was a strange thing. The offline scanning part has a resident php process to process the detected spam information. The resident php process always exits unexpectedly. Php code example :? Phpwhile (1) {$ contentfgets (STDIN); if (empty ($ content )){

Background recently, an anti-spam platform was set up for XX Project. The results were good, but there was a strange thing. The offline scanning part has a resident php process to process the detected spam information. The resident php process always exits unexpectedly. Php code example :? Phpwhile (1) {$ content = fgets (STDIN); if (empty ($ content )){

Background

Recently, an anti-spam platform was set up for XX Project. The results were good, but there was a strange thing. The offline scanning part has a resident php process to process the detected spam information. The resident php process always exits unexpectedly. Php code example:

 
Troubleshooting Process

The initial idea was that the php process exited due to a fatal error during php Execution. Well, we use register_shutdown_function to track the process exit caused by any errors. (For more information about register_shutdown_function, see the blog? Use register_shutdown_function and fastcgi_finish_request in php to add error capture code. As follows:

 

However, the php process exits again. However, no information is recorded in the log. It indicates that the register_shutdown_function method is not executed at all. What causes the register_shutdown_function method to not run? Another comment in the official php document is as follows:

Shutdown functions will not be executed if the process is killed with a SIGTERM or SIGKILL signal. while you cannot intercept a SIGKILL, you can use pcntl_signal () to install a handler for a SIGTERM which uses exit () to end cleanly.

The comment means that when the php process exits after the SIGTERM and SIGKILL signals are obtained, the register_shutdown_function method is not executed. You can use the pcntl_signal () method to capture information and call the corresponding processing method.

Okay. Is that a signal that causes the php process to exit? Add the following code:

 

After a while, I found that the php process has exited and the following log information appears in the log:
2014-11-23 18:30:06 exit signo [14]
18:30:06 [error] is_end [no]

It seems that the sigalarm signal caused the php process to exit. This signal can be captured and processed. We can ignore this insignificant signal. The final code is as follows:

 

After some observation, the alarm-related logs are found in the log, but the php process is still in progress. It seems that our changes have taken effect.

Original article address: The Troubleshooting process of a strange php process exit. Thank you for sharing it with the original author.

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.