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.