I battled a day and found conclusion it can not be done. I put away my php scripts and rewrote it in perl also it labored immediately generate an income wanted results. Still, I wish to discover if such trivial task can be achieved properly in PHP. The question: I've randomly lengthy (in dimensions and time) file upload (via raw data Publish) and that i must save it to some file with PHP. The actual way it works together with PHP is it fist fully processes the published data, saves it to some file after which execution of my script starts (my file upload lasts half an hour). Even when I attempted to fopen("php:/stdin" or php://input) still it labored that retarded way. Things I actually need would be to have the ability to process incoming published data in portions sequentially. I attempted: 1) modphp, 2) php-cgi, 3) php-cli run like a cgi executable. Despite the fact that php-cgi is intended to be used a cgi, still it preprocesses published data (to ensure that $_Publish opens up) and does not work likewise way as regular momphp. CLI version run like a cgi script doens't work, because it can't read from php://stdin or php://input whatsoever! Whatever I attempted, nothing labored for me personally and that i found conclusion it can not be completed with PHP... or it may?


Obviously PHP can perform it. Submitted files are saved inside a temporary directory before the PHP script can communicate with them. The data necessary to do this is incorporated in the $_FILES array.

$field_name = 'file'; # from the HTML form control

$move_result = move_uploaded_file(

if ($move_result) {
    print "successfully uploaded file (originally called '$_FILES[$field_name]['name']' to $real_destfile";
} else {
    print "failed to receive uploaded file.";

it may sound like you need to stream data. to achieve that you would need to setup a socket that's prepared to recive data like a stream.. ie replace the apache web server.

Your condition isn't the language, it's the web server. the net server learns port 80, after which does what it really does. Eg write the publish data to file for then start the php script.

you may create a custom port program as if you did with Gem. you might perform the same factor with PHP, and pay attention to port 80, utilizing a command line driven php script, instead of one that's situated inside apache. But PHP isn't the best language to achieve that with.. I recommend Python.

There's an overhead mounted on HTTP communications, prehaps a slimmer protocol could be useful for you, it might lower your upload time.

in case your upload takes such a long time, you could do this it within an AJAX method, and allow it to continue although the consumer application continues to be active. the customer AJAX application may also perform the work of dividing it into portions.