をありがとう、私はそれがあまりにも高いレベルだように見え、それがstream_socket
家族可能だとは思いません。
それはあなたのために働く場合、私は非常にハック解決策を作ってみました、私はそれを非常に信頼できるではないですが、知らない:
<?php
set_error_handler('my_error_handler');
function my_error_handler($no,$str,$file,$line) {
throw new ErrorException($str,$no,0,$file,$line);
}
$socket = stream_socket_server("tcp://0.0.0.0:8000", $errno, $errstr);
if (!$socket) {
echo "$errstr ($errno)\n";
} else {
while ($conn = stream_socket_accept($socket)) {
foreach (str_split('The local time is ' . date('n/j/Y g:i a') . "\n") as $char) {
echo $char;
try {
fwrite($conn,$char);
} catch (ErrorException $e) {
if (preg_match("/^fwrite\(\): send of 1 bytes failed with errno=([0-9]+) ([A-Za-z \/]+)$/",$e->getMessage(), $matches)) {
list($errno,$errstr) = array((int) $matches[1], $matches[2]);
if ($errno === 32) {
echo "\n[ERROR] $errstr"; // Broken pipe
}
}
echo "\n[ERROR] Couldn't write more on $conn";
break;
}
fflush($conn);
}
fclose($conn);
}
fclose($socket);
}
echo "\n";
?>
打ち上げ:php ./server.php
接続:nc localhost 8000 | head -c1
サーバー出力:
The loca
[ERROR] Broken pipe
[ERROR] Couldn't write more on Resource id #6
回答ありがとうございます。あなたはそれが壊れているかどうかを見るためにいくつかのデータを送信してストリームを騒音することは実現不可能であることを知っているので、現在の状況はサーバーがクライアントのアクションを待っているからです。 – user1304594