Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Detailed introduction of PHP signal processing mechanism

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly explains the "detailed introduction of PHP signal processing mechanism". The content of the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "the detailed introduction of PHP signal processing mechanism".

Let's first take a look at the example code:

Function sig_handler ($sig) {print ("handled sig: $sig\ n");} pcntl_signal (SIGIO, "sig_handler"); posix_kill (posix_getpid (), SIGIO); while (true) {posix_kill (posix_getpid (), SIGIO); pcntl_signal_dispatch (); sleep (1);}

It is best to cycle through the signal queue manually instead of using the signal processing mechanism of declare (ticks=1) and tick_handler () provided by php. Because of the performance problems of the tick mechanism, every statement executed is called back to tick_handler to see if there is a signal, and most of the time there is no signal.

Callback processing of posix_signal setting signal

Posix_kill simply puts the signal into the signal waiting queue of the process, which does not trigger the signal callback, and the pcntl_signal_dispatch processes the signal in the signal queue.

Posix_getpwnam ("nginx"): get the uid,gid and other information of the user name

Pcntl_signal (SIGPIPE, SIG_IGN, false): ignore the SIGPIPE signal sent by the kernel. When the connection has been closed and the process continues to send data to invalid socket, the system will receive a TCP packet with RST control bit, and the system will send a SIGPIPE signal to the process, telling the process that the connection has been disconnected and do not write any more. The default processing of this signal is to terminate the process, and the process can capture it and ignore the signal to avoid being terminated reluctantly.

Socket context options:

Backlog: used to limit the number of outstanding connections in the flow monitoring queue

So_reuseport: reuse port (the kernel schedules multiple processes listening to the same port, and the number of listening processes cannot be changed because the connected processes are marked by hash.)

Timer signal processing

Pcntl_signal (SIGALRM, "sig_handler"); pcntl_alarm (2); function sig_handler ($sig) {echo "one second after";} while (1) {pcntl_signal_dispatch (); sleep (1) Thank you for your reading. The above is the content of "detailed introduction of PHP signal processing mechanism". After the study of this article, I believe you have a deeper understanding of the detailed introduction of PHP signal processing mechanism, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report