기타 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]);
}
?>
기타
- proc_open() - 명령을 실행하고 입출력을 위한 파일 포인터 열기
- sapi_windows_set_ctrl_handler() - CTRL 이벤트 핸들러 설정 또는 제거