Upload files — when does PHP start processing them?

I recently ran into some issues on a shared hosting package due to the fact that I was running synchronous AJAX file uploads. Every file upload created a PHP process and with too many running at a time, PHP ran out of memory. I made them asynchronous, problem solved.

It made me wonder how PHP file uploads work though. When you send a large file does a PHP process get created only once the entire file is uploaded? Does the browser send it to the web server which then creates a PHP process once the file is uploaded? When we talk about file uploads with PHP, really the actual upload (from client to server) isn’t handled by PHP is it? It’s sent in POST.

I’d think that’s the answer - the POST data is sent to the web server and once it arrives in its entirety, the server initiates whatever process is designated in the “action” parameter of that post.

Thanks, it would make sense. Even when you use the HTML5 file API and you get progress data I am assuming that it still done in the same way. The browser just keeps a note of how much it’s sent to the server.

I guess if the script on the server is invoked any time before the entire form post data is uploaded, you’d have the potential for having to deal with incomplete or missing files in your PHP code, or making the server wait somehow if it detects you’re trying to process a file that hasn’t arrived yet, at which point you’re not speeding anything up.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.