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条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 2020长安杯与连接网探
    • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
    • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
    • ¥16 mybatis的代理对象无法通过@Autowired装填
    • ¥15 可见光定位matlab仿真
    • ¥15 arduino 四自由度机械臂
    • ¥15 wordpress 产品图片 GIF 没法显示
    • ¥15 求三国群英传pl国战时间的修改方法
    • ¥15 matlab代码代写,需写出详细代码,代价私
    • ¥15 ROS系统搭建请教(跨境电商用途)