sapi_windows_set_ctrl_handler
Set or remove a CTRL event handler
Description
bool sapi_windows_set_ctrl_handler(callablenull $handler
, bool $add
= true
)
Parameters
-
handler
-
A callback function to set or remove. If set, this function will be called
whenever a
CTRL
C
or
CTRL
BREAK
event occurs.
The function is supposed to have the following signature:
void handler(int $event
)
-
event
-
The CTRL event which has been received;
either
PHP_WINDOWS_EVENT_CTRL_C
or PHP_WINDOWS_EVENT_CTRL_BREAK
.
Setting a null
handler
causes the process to ignore
CTRL
C
events, but not
CTRL
BREAK
events.
-
add
-
If true
, the handler is set. If false
, the handler is removed.
Return Values
Returns true
on success or false
on failure.
Examples
Example #1 Basic sapi_windows_set_ctrl_handler Usage
This example shows how to intercept CTRL
events.
<?php
function ctrl_handler(int $event)
{
switch ($event) {
case PHP_WINDOWS_EVENT_CTRL_C:
echo "You have pressed CTRL+C\n";
break;
case PHP_WINDOWS_EVENT_CTRL_BREAK:
echo "You have pressed CTRL+BREAK\n";
break;
}
}
sapi_windows_set_ctrl_handler('ctrl_handler');
while (true); // infinite loop, so the handler can be triggered
?>
See Also
- sapi_windows_generate_ctrl_event