請問 php 的 feof 沒辦法判斷二進位檔案的結尾嗎?
我今天 google 了一整天都找不到解決方法
在 php 官網也看到有其他人提出同樣問題
http://bugs.php.net/bug.php?id=35136
但並沒有提到解決方法呀!!?? 因此想請教各位高手有無解決辦法呢?
以下是小弟寫的 socks5 連線代碼 function SOCKS ($IP, $Port)
{
if (!$this -> Timeout) $this -> Timeout = 5;
if ($this -> Socket = fsockopen ($IP, $Port, $ErrorNO, $ErrorMessage, $this -> Timeout)) {
fwrite ($this -> Socket, pack ('C3', 0x05, 0x01, 0x00));
while (!feof ($this -> Socket)) $Responce .= fread ($this -> Socket, 0xff); //這行會找不到 EOF 變成無窮回圈
$Result = unpack ('CVER/CMETHOD', $Responce);
if ($Result['METHOD'] == 0x00) return true;
}
return false;
}請不吝解答,謝謝大家.
我今天 google 了一整天都找不到解決方法
在 php 官網也看到有其他人提出同樣問題
http://bugs.php.net/bug.php?id=35136
但並沒有提到解決方法呀!!?? 因此想請教各位高手有無解決辦法呢?
以下是小弟寫的 socks5 連線代碼 function SOCKS ($IP, $Port)
{
if (!$this -> Timeout) $this -> Timeout = 5;
if ($this -> Socket = fsockopen ($IP, $Port, $ErrorNO, $ErrorMessage, $this -> Timeout)) {
fwrite ($this -> Socket, pack ('C3', 0x05, 0x01, 0x00));
while (!feof ($this -> Socket)) $Responce .= fread ($this -> Socket, 0xff); //這行會找不到 EOF 變成無窮回圈
$Result = unpack ('CVER/CMETHOD', $Responce);
if ($Result['METHOD'] == 0x00) return true;
}
return false;
}請不吝解答,謝謝大家.
如果服务器没有关闭由 fsockopen() 所打开的连接,feof() 会一直等待直到超时而返回 TRUE。默认的超时限制是 60 秒,可以使用 stream_set_timeout() 来改变这个值。
文件指针必须有效,并且必须指向一个由 fopen() 或 fsockopen() 成功打开(但还没有被 fclose() 关闭)的文件。
警告
如果传递的文件指针无效可能会陷入无限循环中,因为 EOF 不会返回 TRUE。 例 1. 使用无效文件指针的 feof() 例子<?php
// 如果文件不可读取或者不存在,fopen 函数返回 FALSE
$file = @fopen("no_such_file", "r");// 来自 fopen 的 FALSE 会发出一条警告信息并在这里陷入无限循环
while (!feof($file)) {
}fclose($file);
?>
----------------------------
手册上的警告,你看看有没有帮助?
do{
$tmp = fread ($this -> Socket, 0xff);
$Responce .= $tmp;
} while (!feof ($this -> Socket) && !empty($tmp));