doumengjing1500 2014-09-01 13:03
浏览 32

服务器响应使用php read_file MP3减速

I have a project for a user that has a gallery of uploaded mp3 files that are stored outside of the httpdocs file tree and are being accessed via a php readfile() function. The function works, but the page itself is impossibly slow to load.

I have a php file that is being called as the src for each audio file which I have used in several applications.

$sql='SELECT `name`,`file`, `filetype`,`access` FROM `'.$DBtable.'` WHERE `id`="'.intval($_GET['file']).'";';
$database->setQuery($sql);
$file=$database->loadObject();
//Check access against my access only if the file is restricted
if($file->access>0)
{
$access=isAuth($database);
    if($access<$file->access)
        {
        die('Restricted Access');
        }
}
    $uploaddir=BASE_URI;
$filename=$file->file;
    switch ($file->filetype) { 
  case "pdf": $ctype="application/pdf"; break; 
  //case "exe": $ctype="application/octet-stream"; break; 
  case "zip": $ctype="application/zip"; break; 
  case "doc": $ctype="application/msword"; break; 
  case "xls": $ctype="application/vnd.ms-excel"; break; 
  case "ppt": $ctype="application/vnd.ms-powerpoint"; break; 
  case "gif": $ctype="image/gif"; break; 
  case "png": $ctype="image/png"; break; 
  case "jpeg": 
  case "jpg": $ctype="image/jpg"; break;
  case "mp3": $ctype="audio/mpeg";break;
  case "ogg": $ctype="audio/ogg"; break; 
  default: $ctype="application/force-download"; 
} 
header('Content-type: '.$ctype);
header('Content-Disposition: attachment; filename="'.$file->name.'.'.$file->filetype.'"');
readfile($uploaddir.$filename);

The page itself is calling

<img data-src="file.php?source=images&file=668" class="thumbnail" parent="667">
<audio class="gallery_audio" controls="controlls">
<source src="audio_file.php?file=123" type="audio/mpeg">
    <source src="audio_file.php?file=124" type="audio/ogg">
Your browser does not support the audio element.
</audio>

where file.php and audio_file.php are copies of the file loading php code. I have tried creating multiple copies of these files to spread out the http requests, thinking that maybe the server was being overloaded by repeated requests for the same file, *there are only 10, but still no love. Also it does appear that FF consistently handles this better than IE or Chrome. When I am only loading images, it seems to respond better even for much larger quantities of requests. These are very small audio files. 50-90KB so size should not be major issue.

Is there a better direction to be headed for audio files? Lazy load helps with the images, but does not seem to help much with the audio.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥20 蓝牙耳机怎么查看日志
    • ¥15 Fluent齿轮搅油
    • ¥15 八爪鱼爬数据为什么自己停了
    • ¥15 交替优化波束形成和ris反射角使保密速率最大化
    • ¥15 树莓派与pix飞控通信
    • ¥15 自动转发微信群信息到另外一个微信群
    • ¥15 outlook无法配置成功
    • ¥30 这是哪个作者做的宝宝起名网站
    • ¥60 版本过低apk如何修改可以兼容新的安卓系统
    • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏