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

How to implement a signal interrupt system in PHP

2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

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

In this issue, the editor will bring you about how to achieve a signal interrupt system in PHP. The article is rich in content and analyzes and describes for you from a professional point of view. I hope you can get something after reading this article.

The interrupt system has nothing to do with PHP, but PHP's official pcntl extension supports it. Generally speaking, the program being executed is called the main program. When the interrupt source [for example, hardware interrupt event caused by keyboard pressing ctrl+c,ctrl+z, etc.] initiates an interrupt request event [interrupt signal], the main program will accept the interrupt request and stop the currently running program, and then go to the interrupt service program to run [interrupt response]. The interrupt service program is also known as the interrupt handler, and the place where the program interrupts is called the breakpoint. After the completion of the interrupt service program processing, the interrupt service program returns to the breakpoint to continue execution, which is called interrupt return.

The above is a complete interrupt handling process.

Interrupt source

Hardware-generated interrupts: keyboard [these are only available to most people, such as interrupts generated by ctrl_c,ctrl+z, SIGINT,SIGTSTP, etc.]

Software-generated interrupts: interrupts caused by the exit of a child process of a process, timing signals, interrupts sent by kill or from one process to another, interrupts caused by changes in file descriptors, etc.

Interrupt signal:

Signal list description

Interrupt handling:

1. Perform the default action

2. Ignore

3. Execute user-defined signal processing function [capture]

Example of interrupt signal processing [PHP manual]

Echo "install signal processor.\ n"

Pcntl_signal (SIGHUP, function ($signo) {/ / interrupt handler

Echo "signal processor called\ n"

});

Echo "generates SIGHUP signals for itself.\ n"

Posix_kill (posix_getpid (), SIGHUP); / / generate an interrupt request

Echo "distribute.\ n"

Pcntl_signal_dispatch ()

Echo "done\ n"

Signal sets and blocking:

1. The action of processing when the signal arrives

2. Signal undetermined set

3. Signal blocking set

The process can choose to block a signal, which, when generated, will be placed in the unresolved set and cannot be captured unless the blocking has been unblocked.

Signal set operation

1. Initialize a signal set [sigemptyset]

2. Add / remove signals [sigaddset,sigdelset]

3. Determine whether a signal belongs to a set [sigismember].

4. Signal set blocking function sigprocmask [pcntl_sigprocmask]

5. Pending signal set sigpending

6. Signal processing function signal, sigaction [pcntl _ signal]

Signal blocking test: [the signal cannot be delivered, it can only be in the pending set, you can view / proc/PID/status 's signal processing]

Detect the existence of a process [signal to the process group]

Posix_kill (posix_getpid (), 0)

Limitations of signal [soft interrupt]:

1. The system cost of the signal is too high.

2. The process that sends the signal should make a system call.

3. The kernel interrupts the process that receives the signal, manages its stack, calls the handler, and then resumes the interrupted process that is executed.

4. The number of signals is very limited [64 are supported by linux]

5. The amount of information that the signal can transmit is very limited, and the signal generated by the user can not add all kinds of information and parameters.

The above is how to achieve a signal interrupt system in the PHP shared by the editor. If you happen to have similar doubts, you might as well refer to the above analysis to understand. If you want to know more about it, you are welcome to follow the industry information channel.

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: 212

*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

Internet Technology

Wechat

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

12
Report