I am using the file uploader plugin (from: https://github.com/valums/file-uploader) to upload files to my website.

If you are using a moden web browser (like Firefox 6 or Chrome 13), then it uploads by streaming the file in the POST body, and can give you a progress bar. If you're using IE (or an old browser), it falls back on the standard $_FILES (using a hidden iFrame).

Everything was working fine, but suddenly I can't upload 5MB files in Chrome or Firefox. When I upload a 5MB file in Chome or Firefox I get a 500 error and my PHP code is never even ran. If I use Internet Explorer (which uses $_FILES), it works fine.

This has to be a configuration problem, as my PHP code never even runs. So, I checked my settings.


upload_max_filesize = 15M
post_max_size = 16M

I looked for LimitRequestBody, but that's nowhere to be found (and the default is unlimited).

Settings look right. I debugged this for a while, and I can not figure out what is wrong.

Is there a setting I'm missing? The server has suhosin installed, if that matters.

I know my PHP code works, as files less than 4MB upload fine (on all browsers). I only have a problem with files bigger than 5MB (using Chrome/Firefox). The weird thing is, this works fine on my test server, but not my production server. They probably have different settings (suhosin is on production, but not on test).

  • Are there any messages in your web server logs? – voretaq7 Sep 21 '11 at 15:40
  • 1
    @voretaq7: PHP Fatal error: Allowed memory size of 16777216 bytes exhausted (tried to allocate 5242881 bytes). Let's change memory_limit to 64M, see if that works. – Rocket Hazmat Sep 21 '11 at 15:55
  • @voretaq7: Changing memory_limit to 64M worked! But will that be a problem if multiple people are uploading at the same time? – Rocket Hazmat Sep 21 '11 at 15:59
  • It shouldn't be -- how much RAM does your server have and how many concurrent connections are you expecting? (64M or 128M is what I usually set PHP to on machines with 4-8GB of RAM - the chance of every apache process sucking up that much RAM is infinitesimal unless you have an extreme use case...) – voretaq7 Sep 21 '11 at 17:50
  • @voretaq7: 2GB, I think. But if I have 100 people all uploading 10MB files at the same time, that'd be 1GB. – Rocket Hazmat Sep 21 '11 at 18:13

I think the problem is here and specifically in the stream_copy_to_stream () which seems to be a memory hog because (and I only assume) it copies the whole(?) file to be uploaded to memory. So check suhosin.memory_limit and memory_limit in php.ini

PS I don't know the etiquette here if I should submit it as an answer or a comment, but I'll leave it as an answer for the time.

  • 1
    memory_limit was the culprit. I changed it to 64M and, it's working. I wonder if an alternative to stream_copy_to_stream will help. – Rocket Hazmat Sep 21 '11 at 16:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.