1
在PHP中,我打開一個流,寫入它,然後從它讀取。我想設置流的讀取超時,但無論我設置了多少(0微秒,10微秒),元數據都不會顯示「timed_out」!stream_set_timeout永遠不會工作,無論多麼低的超時
相關代碼:
//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);
}
}
}
我在做什麼錯?
您正在CLI或瀏覽器中執行此操作嗎? – Pheonix