php 메모리 사용않고 바로 받을수 있게 하는법 아시는분?? 정보
그누보드 php 메모리 사용않고 바로 받을수 있게 하는법 아시는분??본문
댓글 전체
감사합니다..^^
<?php
$file = "test.mp3"; // file to be send to the client
$speed = 8.5; // 8,5 kb/s download rate limit
if(file_exists($file) && is_file($file)) {
header("Cache-control: private");
header("Content-Type: application/octet-stream");
header("Content-Length: ".filesize($file));
header("Content-Disposition: filename=$file" . "%20");
flush();
$fd = fopen($file, "r");
while(!feof($fd)) {
echo fread($fd, round($speed*1024));
flush();
sleep(1);
}
fclose ($fd);
}
?>
위의 소스를 응용해 보십시오.
간단한 스트리밍서비스를 구현하는 소스인데..
flush, sleep 함수가 네트웍트래픽과 서버부하를 다소 줄여주는 역할을 합니다.
$speed 값을 알맞게 해주면 트래픽 조절이 가능해집니다.
아래 flush 관련 링크입니다.
http://kr.php.net/manual/kr/function.flush.php
$file = "test.mp3"; // file to be send to the client
$speed = 8.5; // 8,5 kb/s download rate limit
if(file_exists($file) && is_file($file)) {
header("Cache-control: private");
header("Content-Type: application/octet-stream");
header("Content-Length: ".filesize($file));
header("Content-Disposition: filename=$file" . "%20");
flush();
$fd = fopen($file, "r");
while(!feof($fd)) {
echo fread($fd, round($speed*1024));
flush();
sleep(1);
}
fclose ($fd);
}
?>
위의 소스를 응용해 보십시오.
간단한 스트리밍서비스를 구현하는 소스인데..
flush, sleep 함수가 네트웍트래픽과 서버부하를 다소 줄여주는 역할을 합니다.
$speed 값을 알맞게 해주면 트래픽 조절이 가능해집니다.
아래 flush 관련 링크입니다.
http://kr.php.net/manual/kr/function.flush.php
flush 함수가 몬지요??
힌트라도 ...
힌트라도 ...
flush 함수를 사용해 보십시오.
일정량 만큼 읽을수 있는 루프를 돌려서 flush 함수로 버퍼를 비워주면 될듯싶습니다.
물론 서비스 프로세스가 지속되어 늘어나는 현상은 발생하겠지만 서버가 다운로드가 아주 많기 전에는 서버가 뻗어버리는 것은 어느정도 방지할수 있을듯 합니다.
일정량 만큼 읽을수 있는 루프를 돌려서 flush 함수로 버퍼를 비워주면 될듯싶습니다.
물론 서비스 프로세스가 지속되어 늘어나는 현상은 발생하겠지만 서버가 다운로드가 아주 많기 전에는 서버가 뻗어버리는 것은 어느정도 방지할수 있을듯 합니다.