Mp3流媒体/下载网站 - apache服务器内存问题

I have a website, in which users can upload mp3 files (uploadify), stream them using an html5 player (jplayer) and download them using a php script (www.zubrag.com/scripts/).

When a user uploads a song, the path to the audio file is saved in the database and i'm using that data in order to play and show a download link for the song. The problem that i'm experiencing is that, according to my host, this method is using a lot of memory on the server, which is dedicated.

Link to script: http://pastebin.com/Vus8SRa7

How should I handle the script properly? And what would be the best way to track down the problem? Any ideas on cleaning up the code?

Any help much appreciated.

I would recommend storing your files on disk (named something random [check for collisions!] or sequential, without file extension, and outside of the doc root), and only store information in your DB. It's much easier to stream a file from disk this way than it is out of a database result.

When you retrieve an entire file's contents out of a database result, that data has to be in memory. readfile() doesn't have this issue. Use headers to return the original file name when sending the file back to the client, if you wish.

I would suggest you not to buffer the content when you are writing binary data of the MP3 onto your HTTP output. That way you'd be saving a lot on physical and virtual memory usage.