Connecting Tech Pros Worldwide Forums | Help | Site Map

Make file upload as fast as download, (no n00b)

dlite922's Avatar
Expert
 
Join Date: Dec 2007
Location: Moon, Dark Side
Posts: 1,095
#1: Jun 19 '09
Before you jump in front of the train, no I don't mean ISP wise. I know providers throttle speed towards download.

This is in a two PC LAN and one user. one average PC is a RedHat 'LAMP' server and the other is an XP desktop.

The same file that is uploaded is downloaded much faster (ie 1 minutes to upload, 5 seconds to download)

Is it just how HTTP file uploads work? is it PHP? I've simplified my code to one file with one form and one move_uploaded_file() call. something that is completely stripped, if you insist, I'll give you the code.

To me it seems like it should be the same speed in this environment: same NIC speed, same LAN, similar processing power/hard drive speeds.

I'm looking mostly for an explanation because google results are infested with ISP related topics, which is not the case with me.

Thanks as always,




Dan

Atli's Avatar
Moderator
 
Join Date: Nov 2006
Location: Iceland
Posts: 3,748
#2: Jun 19 '09

re: Make file upload as fast as download, (no n00b)


Hi.

I don't see why that would be either. A LAN connection is certainly capable of uploading at the same speed as downloading. (The distinction is only for our benefit. They are the same thing, really.)

I suppose it is possible that you PHP code, or some other software limitation on the receiving end (memory limits and such) are making it appear the upload is slower, while in reality it's just taking the server forever to process the file.
If your doing some sort of image processing, for instance, then that could take a while.

Other than that, I don't know. Maybe the browser your using is doing something to slow it down... validating the file before sending or something like that.

... I'm going to test this on my network, see it is is the same here.
Markus's Avatar
Moderator
 
Join Date: Jun 2007
Location: York, England, with wolves.
Posts: 4,947
#3: Jun 19 '09

re: Make file upload as fast as download, (no n00b)


Quote:

Originally Posted by Atli View Post

... I'm going to test this on my network, see it is is the same here.

Me too. ETA (report): 10 mins.
Atli's Avatar
Moderator
 
Join Date: Nov 2006
Location: Iceland
Posts: 3,748
#4: Jun 19 '09

re: Make file upload as fast as download, (no n00b)


I tried this on my local network.

Server is:
Quote:
Apache/2.2.9 (Ubuntu) PHP/5.2.6-2ubuntu4.2 with Suhosin-Patch mod_ssl/2.2.9 OpenSSL/0.9.8g Server at advefir-dev Port 80
Changed upload_max_filesize and post_max_size to 500M, and the memory_limit to 128M.

Uploaded a 350Mb file in ~30 seconds.
Downloaded it in ~29 seconds.

Tried it several times. Always pretty much the same upload/download speeds.
dlite922's Avatar
Expert
 
Join Date: Dec 2007
Location: Moon, Dark Side
Posts: 1,095
#5: Jun 19 '09

re: Make file upload as fast as download, (no n00b)


Quote:

Originally Posted by Atli View Post

I tried this on my local network.

Server is:


Changed upload_max_filesize and post_max_size to 500M, and the memory_limit to 128M.

Uploaded a 350Mb file in ~30 seconds.
Downloaded it in ~29 seconds.

Tried it several times. Always pretty much the same upload/download speeds.

WOW Atli! Thanks! That gives me some hope.

I'm not doing any processing and tried with IE6/GC/FF, except moving it from the PHP temp directory to the web folder where it can URL accessed.

I have Apache 2.2, PHP 5.1.6 Linux Redhat (9?) 2.6 kernel.

I'm going to do some more testing and see if I find the cause of my time difference.



Dan


PS: Someone else has a CMS with file uploading (on the same server). I tested it and got similar or longer results for upload and very quick download. so i don't think it's code but, Atli's test got me curious.
dlite922's Avatar
Expert
 
Join Date: Dec 2007
Location: Moon, Dark Side
Posts: 1,095
#6: Jun 19 '09

re: Make file upload as fast as download, (no n00b)


TEST RESULTS:

3.2MB file took 63 seconds ^upload^ and 13 seconds to download.

Question remains: if it's my server, what's it doing?

I have a windows (WAMP) install at home, i'm going to run the following code at home as well and record the resullts.

test.php:

Expand|Select|Wrap|Line Numbers
  1.  
  2. <?php
  3. /**
  4. * Test file upload and download speed, manually timeing it 
  5. */
  6. $destination = "/tmp/testFile.txt";  // where the file should be saved (apache must have access)
  7. $fileUploaded = false; // flag to display download button. 
  8.  
  9. // FIRST PAGE
  10. if($_POST['submit']) 
  11. {
  12.     move_uploaded_file($_FILES['testFile']['tmp_name'],$destination);
  13.     $uploadTook = round(microtime(true) - ($_POST['startUploadTS']/1000),5);
  14.     $fileUploaded = true; 
  15. }
  16.  
  17. // SECOND PAGE
  18. if($_POST['downloadFile']) 
  19. {
  20.     if(file_exists("/tmp/testFile.txt")) 
  21.     {
  22.         // commented out headers to output file to screen and not wait to open/save dialogue box. uncomment to see dialogue box. 
  23.         //        header('Content-Description: File Transfer');
  24.         //        header('Content-Type: application/octet-stream');
  25.         //        header('Content-Disposition: attachment; filename=test.txt');
  26.         //        header('Content-Transfer-Encoding: binary');
  27.         //        header('Expires: 0');
  28.         //        header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
  29.         //        header('Pragma: public');
  30.         //        header('Content-Length: ' . filesize($destination));
  31.         $begin = microtime(true); 
  32.         ob_clean();
  33.         flush();    
  34.           echo file_get_contents($destination); 
  35.           echo "<hr><br><br>Download took: ", round((microtime(true) - $begin),5), " MS"; 
  36.           exit(); 
  37.     }    
  38. }
  39.  
  40. ?>
  41. <html>
  42.     <body>
  43. <?php if ($fileUploaded) {?>
  44.  
  45.         <form name="global" id="global" action="" method="post" enctype="multipart/form-data">
  46.             <input type="submit" name="downloadFile" value="Click Here To Download File"><br />
  47.             Upload Took: <?php echo $uploadTook ?> MS
  48.         </form>
  49.  
  50. <?php } else { ?>
  51.  
  52.         <form name="global" id="global" action="" method="post" enctype="multipart/form-data">
  53.             <input type="hidden" name="startUploadTS" id="startTime" value="" />
  54.             <input type="file" name="testFile" id="testFile" /> 
  55.             <input type="submit" name="submit" value="Upload ^" onclick="document.getElementById('startTime').value = new Date().valueOf()" />
  56.         </form>
  57.  
  58. <?php } ?>
  59.     </body>
  60. </html> 
  61.  
  62.  

Feel free to run this on your *test* (not live) server as well.
Reply