sapi_windows_set_ctrl_handler
sapi_windows_set_ctrl_handler
Set or remove a CTRL event handler
bool **sapi_windows_set_ctrl_handler** $handler bool $add
Sets or removes a event handler, which allows Windows
CLI processes to intercept or ignore and
events. Note that in multithreaded environments,
this is only possible when called from the main thread.
CTRL``CTRL+C``CTRL+BREAK
handler
A callback function to set or remove. If set, this function will be called
whenever a
or
event occurs.
The function is supposed to have the following signature:
Setting a null causes the process to ignore
events, but not
events.
```php
void handler int $event
`event`
The event which has been received;
either
or .
`PHP_WINDOWS_EVENT_CTRL_C``PHP_WINDOWS_EVENT_CTRL_BREAK`
`handler`
`add`If true, the handler is set. If false, the handler is removed.
return.success
**Voorbeeld: Basic Usage**
This example shows how to intercept events.
`CTRL`
```php
<?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
?>
sapi_windows_generate_ctrl_event