Php – Apache2 memory usage when uploading large files

apache-2.2memoryPHP

I am running apache2.2.12 along with PHP 5.2.10. PHP is configured to run as a separate process through fcgid. The problem is that when users upload a file, size of the apache process swells by almost the same amount. So if somebody tries to upload a 200 MB file, one of the child process swells to current size+200 MB. If 2 users simultaneously start uploading, my server crashes.

Now it is the virtual memory size which is increasing but since I am on a OpenVZ based VPS, that is what counts.

My questions are:

  • Is it the normal Apache behavior or can I do something to fix this?
  • If not, is there a more memory efficient way of handling big file uploads. Going by the current behavior, I will need 1 GB of free RAM for every apache child accepting a upload.

Thanks!

Abhaya

Best Answer

Interesting issue, and it seems to be a limitation of php. See the following:

They both in the end seem to say "Use java or Perl" or something else. Perhaps someone on stackoverflow has the answer. For uploads this large, sftp might be the better solution depending on how user friendly this needs to be.

If you are willing to use non-php, JUpload looks like a good option since it can break the file into chunks and flush out each chunk to disk. If it has to be php, it looks like you might be able to roll out something custom with some socket programing according to this stackoverflow post.

At this size, you probably want something with resume and progress capability anyways.