기타 sapi_windows_generate_ctrl_event

(PHP 7 >= 7.4.0, PHP 8)

sapi_windows_generate_ctrl_event — 다른 프로세스에 CTRL 이벤트 보내기


설명

sapi_windows_generate_ctrl_event(int $event, int $pid = 0): bool

같은 프로세스 그룹의 다른 프로세스에 CTRL 이벤트를 보냅니다.


매개변수

event
CTRL을 보낼 수도 있습니다. PHP_WINDOWS_EVENT_CTRL_C 또는 PHP_WINDOWS_EVENT_CTRL_BREAK.
pid
이벤트를 보낼 프로세스의 ID입니다. 0이 주어지면 이벤트는 프로세스 그룹의 모든 프로세스로 전송됩니다.

반환 값

성공하면 true를, 실패하면 false를 반환합니다.


Examples

예제 #1 기본 sapi_windows_generate_ctrl_event() 사용법

이 예는 CTRL+BREAK 이벤트를 자식 프로세스에 전달하는 방법을 보여줍니다. 이 경우 자식 프로세스는 사용자가 CTRL+BREAK를 누를 때까지 매초마다 I'm still alive를 에코합니다. 이로 인해 자식 프로세스만 종료됩니다.

                  
<?php
// forward CTRL+BREAK events to the child process
sapi_windows_set_ctrl_handler('sapi_windows_generate_ctrl_event');

// create a child process which echoes every second
$cmd = ['php', '-r', 'while (true) { echo "I\'m still alive\n"; sleep(1); }'];
$descspec = array(['pipe', 'r'], ['pipe', 'w'], ['pipe', 'w']);
$options = ['create_process_group' => true];
$proc = proc_open($cmd, $descspec, $pipes, null, null, $options);
while (true) {
    echo fgets($pipes[1]);
}
?>
                  
                

기타