array ( 0 => 'index.php', 1 => 'PHP Manual', ), 'head' => array ( 0 => 'UTF-8', 1 => 'ja', ), 'this' => array ( 0 => 'function.sapi-windows-generate-ctrl-event.php', 1 => 'sapi_windows_generate_ctrl_event', ), 'up' => array ( 0 => 'ref.misc.php', 1 => 'その他の関数', ), 'prev' => array ( 0 => 'function.sapi-windows-cp-set.php', 1 => 'sapi_windows_cp_set', ), 'next' => array ( 0 => 'function.sapi-windows-set-ctrl-handler.php', 1 => 'sapi_windows_set_ctrl_handler', ), 'alternatives' => array ( ), 'source' => array ( 'lang' => 'ja', 'path' => 'reference/misc/functions/sapi-windows-generate-ctrl-event.xml', ), ); $setup["toc"] = $TOC; $setup["toc_deprecated"] = $TOC_DEPRECATED; $setup["parents"] = $PARENTS; manual_setup($setup); ?>
(PHP 7 >= 7.4.0, PHP 8)
sapi_windows_generate_ctrl_event — CTRLイベント を別プロセスに送信する
同じプロセスグループの別プロセスに CTRLイベント を送信する。
event
送信する CTRL
イベント:
PHP_WINDOWS_EVENT_CTRL_C
または PHP_WINDOWS_EVENT_CTRL_BREAK
pid
イベントを送信するプロセスID。
0
に設定すると、プロセスグループに属する
全てのプロセスにイベントが送信されます。
例1 sapi_windows_generate_ctrl_event() 関数の基本的な使い方
以下の例は、 CTRL+BREAK
イベントを子プロセスに送信する方法を示しています。
この場合、ユーザーが CTRL+BREAK
を押すまで、
子プロセスは I'm still alive
を1秒ごとに表示します。
CTRL+BREAK
は、子プロセスのみを終了させます。
<?php
// CTRL+BREAK イベントを子プロセスに送信する
sapi_windows_set_ctrl_handler('sapi_windows_generate_ctrl_event');
// 1秒ごとに echo する子プロセスを生成
$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]);
}
?>