Search code examples
phpmp3readfile

Reading a File with PHP gives 500 error


I have a script which reads a mp3 file with readfile() (I have also tried fread() with a loop). And on one particular file I am getting a 500 error. All other files seem to read just fine.

When I review the error log on my server I notice I am getting a PHP memory error when ever this particular file is attempted to be read.

Can anyone give me some pointers as to what might be going on?


Solution

  • You already pointed out the problem - PHP is running out of memory. Maximum memory usage in PHP is limited by an ini setting.

    You can set it at runtime at the top of your script with ini_set:

    ini_set('memory_limit', '64M');
    

    Or you can set it in your php.ini file so it takes effect for all scripts:

    memory_limit = 64M;
    

    Finally, you can see the memory used by the currently executing script with memory_get_usage()