This can be done with proc_open. For example, this program allows you to run ping6within 5 seconds:
<?php
$descriptorspec = array(
1 => array("pipe", "w"),
);
$process = proc_open('ping6 ::1', $descriptorspec, $pipes);
$emptyarr = array();
$start = microtime(true);
if (is_resource($process)) {
stream_set_blocking($pipes[1], 0);
while (microtime(true) - $start < 5) {
$pipesdup = $pipes;
if (stream_select($pipesdup, $emptyarr, $emptyarr, 0, 100000))
echo fread($pipes[1], 100);
}
fclose($pipes[1]);
proc_terminate($process);
}
In your case, you can check connection_aborted(). But note that you must continue to send (and flush) data to interrupt the user that will be detected.