开发者

How to find the optimum length of transfer in fread function

开发者 https://www.devze.com 2023-04-10 14:57 出处:网络
There are files with unknown file size ( not included in header as content-length) I am trying to copy them to my server using this:

There are files with unknown file size ( not included in header as content-length) I am trying to copy them to my server using this:

$file='';
do{
    $line = @fread ( $fp, 16384 );
    $file .= $line;
}while ( strlen($line)> 0 );

the file is always pdf content. The problem is sometimes it gets the file (153 Kb) and sometimes it gets the part of file (3kb) and sometimes it hangs and the cpu of my computer works with 100% usage!!

what do you suppose to do ? any thisg wrong with length ( 16384 ) ?

=============== edit ================ more information

$request = $method . " " . $url . " HTTP/1.1" . $nn . "Host: " . $host . $nn . "User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.14) Gecko/20080404 Firefox/2.0.0.14" . $nn . "Accept: */*" . $nn . "Accept-Language: en-us;q=0.7,en;q=0.3" . $nn . "Accept-Charset: utf-8,windows-1251;q=0.7,*;q=0.7" . $nn . "Pragma: no-cache" . $nn . "Cache-Control: no-cache" . $nn . ($Resume ["use"] === TRUE ? "Range: bytes=" . $Resume ["from"] . "-" . $nn : "") . $http_auth . $proxyauth . $referer .($XMLRequest ? "X-Requested-With: XMLHttpRequest" . $nn : ""). $cookies . "Connection: Close" . $nn . $content_tl . $nn . $postdata;
$fp = @fsockopen($Host , $Port, $errno, $errstr, 15);
fputs ( $fp, $r开发者_运维百科equest );
fflush ( $fp );
$file='';
    do{
        $line = @fread ( $fp, 16384 );
        $file .= $line;
    }while ( strlen($line)> 0 );
0

精彩评论

暂无评论...
验证码 换一张
取 消