Function name: sapi_windows_set_ctrl_handler()
Function Description: The sapi_windows_set_ctrl_handler() function is used to set the handler for capturing control signals on Windows platforms.
Applicable version: PHP 4 >= 4.2.0, PHP 5, PHP 7
Syntax: bool sapi_windows_set_ctrl_handler ( callable $callback [, bool $add = true ] )
parameter:
Return value: Return true on success, and false on failure.
Example:
<?php function my_handler($signal) { echo "Received signal: " . $signal . "\n"; } // 添加控制信号的处理程序sapi_windows_set_ctrl_handler('my_handler'); // 模拟发送控制信号posix_kill(posix_getpid(), SIGINT); ?>
Output:
Received signal: 2
In the above example, a callback function my_handler()
is first defined, which will be called when a control signal is received. Then use the sapi_windows_set_ctrl_handler()
function to set my_handler()
as the handler for the control signal. Finally, a SIGINT
control signal is sent by using the posix_kill()
function, causing my_handler()
function to be called and the corresponding signal value is output.