PHPでは、ストリームを開いて書き込み、読み取りを行っています。ストリームの読み取りにタイムアウトを設定したいのですが、これをどれだけ低く設定しても(0マイクロ秒、10マイクロ秒)、メタデータに「timed_out」が表示されることはありません。
関連コード:
//open the socket
if ( $fp = fsockopen( gethostbyname(host), port, $errno, $errstr, $timeout ) ) {
//Send command to the host
if ( fwrite( $fp, $requestCommand ) ) {
//Set timeout and blocking
stream_set_blocking( $fp, FALSE );
stream_set_timeout( $fp, 0, 10 );
//Check for timeout
$info = stream_get_meta_data( $fp );
echo $info[ 'timed_out' ];
//Read and check for timeout
while ( !$info['timed_out'] && !feof( $fp ) ) {
$response .= fread( $fp, 4096 );
//Get meta data (which has timeout info)
$info = stream_get_meta_data( $fp );
}
}
}
私は何が間違っているのですか?