sapi_windows_generate_ctrl_event

(PHP 7 >= 7.4.0, PHP 8)

sapi_windows_generate_ctrl_event — Belirtilen sĂŒrece bir CTRL olayı gönderir

Açıklama

function sapi_windows_generate_ctrl_event(int $olay, int $pid = 0): bool

Aynı sĂŒreç grubundaki baßka bir sĂŒrece belirtilen CTRL olayını gönderir.

Bağımsız Değißkenler

olay

Önderilecek CTRL olayı; PHP_WINDOWS_EVENT_CTRL_C veya PHP_WINDOWS_EVENT_CTRL_BREAK olabilir.

pid

Olayın gönderileceği sĂŒrecin kimliği. 0 belirtilirse olay sĂŒreç grubundaki tĂŒm sĂŒreçlere gönderilir.

Dönen Değerler

Baßarı durumunda true, baßarısızlık durumunda false döner.

Örnekler

Örnek 1 - sapi_windows_generate_ctrl_event() örneği

Bu örnek, CTRL+BREAK olaylarının bir alt sĂŒrece nasıl iletileceğini gösterir. Bu durumda, kullanıcı CTRL+BREAK tußlarına basıp sĂŒreci sonlandırana kadar kadar sĂŒreç her saniye Hala etkinim dizgesini çıktılar.

<?php
// çocuk sĂŒreçlere CTRL+BREAK olaylarını ilet
sapi_windows_set_ctrl_handler('sapi_windows_generate_ctrl_event');

// Her saniye bir çıktı verecek bir sĂŒreç olußtur
$cmd = ['php', '-r', 'while (true) { echo "Hala etkinim\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]);
}
?>

Ayrıca Bakınız

add a note

User Contributed Notes 1 note

up
2
Michael Q ¶
5 years ago
This function may produce a Warning:

sapi_windows_set_ctrl_handler(): CTRL events trapping is only supported on console in script.php..

It happens when script is started by "php-cgi.exe", so "php.exe -q" should be used instead.

While pressing CTRL+C don't expect the handler to run instantly, i've ran some curl request in a loop and found that handler runs when either response arrives or request finishes by timeout.