PHP 스크립트를 통해 URL에서 내 사용자에게 다운로드를 제공하고 있습니다. readfile()
을 사용할 때 내 연결이 지원할 수있는 최대 다운로드 속도 (약 2.5MB/초)를 얻을 수 있지만 fopen, fread, fclose
경로를 사용하면 다운로드 속도가 매우 느리고 (약 1-2KB/초) 느려집니다.readfile보다 다운로드 속도가 훨씬 더 빠름
여기 내 코드입니다 :
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename=' . $filename);
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . $filesize);
ob_clean();
flush();
$file = fopen($url, 'rb');
while(!feof($file)) {
echo fread($file, 2014);
}
과 ReadFile을 코드는 단순히 readfile($link);
입니다.
가 난 그냥 사용자가 (난 단지 너무 많은 데이터를 읽어 fread
로 할 수있는) 속도를 다운로드 제한 할 일이 있기 때문에 두 가지 이유의 readfile()
기능을 사용할 수 없습니다와 나는 또한 얼마나 추적 할 사용자가 다운로드 중입니다 (이 작업은 readfile()
으로 수행 할 수 있지만 부분 다운로드는 계산하지 않음).
왜 이런 일이 일어날 지 또는 어떻게 해결할 수 있는지 아는 사람이 있습니까? 지금까지 내가 알고있는 한 readfile()
은 fopen, fread and fclose
에 대한 래퍼 일 뿐이므로 잘못된 결과가 나지 않습니다.
편집 :이 경우 cURL과 함께 종료되었습니다.
사용 stream_context_create()$curl = curl_init();
$options = array(
CURLOPT_URL => $rdLink,
CURLOPT_FAILONERROR => true,
CURLOPT_BINARYTRANSFER => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_WRITEFUNCTION => 'readResponse'
);
curl_setopt_array($curl, $options);
if(!curl_exec($curl)) {
header('Location: http://whatever.com');
exit;
}
curl_close($curl);
function readResponse($ch, $data) {
$length = mb_strlen($data, '8bit');
echo $data;
return $length;
}
출력 버퍼링이 필요합니까? Try'ob_end_flush();' – Boann
확실치 않지만, 다른 곳에서이 코드를 얻었고 출력 버퍼링이있었습니다. 어디서'ob_end_flush();'를 써야합니까? –
글쓰기를 시작하기 전에 아무 데나 놓으십시오. – Boann