PHP Function PCNTL_Signal
A php function pcntl_signal is part of the PCNTL (Process Control NTL) library that provides process forking and signal handling functions. It can be used to create a child process that sleeps for a specified amount of time and then exits with a certain status value. It can also be used to handle multiple signals at once. The example below uses a queue to hold the child process while waiting for the specified timeout. This is a great way to handle multiple tasks without having the parent process constantly sleep or die.
The pcntl_signal() function installs a new handler for the given signal. It can take a callable, an integer value (such as SIG_DFL or SIG_IGN), or both. If the handler is a callable, it will be invoked to handle the given signal. If the integer value is a global constant, it will replace the current handler for that signal.
This function allows you to register a handler for any signal that is generated by the parent process (pcntl_fork()). If a queued up signal is not handled by its handler, it will be passed on to the next signal handler.
This function is useful when you want to multitask with a process that can only stop if someone sends it a kill command through another terminal. If you don't do this, your script will whizz around forever - it won't stop until either someone hits Ctrl-C or a "kill -9 PID" is sent to the shell.