in reply to optimization of browser upload

Choosing a read() buffer size is largely arbitrary. Making it bigger might help but you'll have to test to know for sure.

My preference would be to just use CGI.pm or Apache::Request (if running under mod_perl) to handle the upload. Chances are their method will be as fast, and far more reliable, than anything you or I would create independently. Just think about how much testing these modules have undergone! How much testing will you do with your code?

-sam

PS. I first misread your question as being about sending files fast. I dove into my copy of the Eagle book and dug out $r->send_fd($fh), which is a really fast way to send files to clients under Apache/mod_perl. No need to loop - just one call and Apache handles the rest with blazingly fast C code that might even use the sendfile() system call if you're lucky. Unfortunately I don't know of anything similar for handling file uploads.