Make file upload as fast as download, (no n00b)  | Expert | | Join Date: Dec 2007 Location: Moon, Dark Side
Posts: 1,095
| | |
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
|  | Moderator | | Join Date: Nov 2006 Location: Iceland
Posts: 3,748
| | | 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.
|  | Moderator | | Join Date: Jun 2007 Location: York, England, with wolves.
Posts: 4,947
| | | re: Make file upload as fast as download, (no n00b) Quote:
Originally Posted by Atli ... I'm going to test this on my network, see it is is the same here. Me too. ETA (report): 10 mins.
|  | Moderator | | Join Date: Nov 2006 Location: Iceland
Posts: 3,748
| | | 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.
|  | Expert | | Join Date: Dec 2007 Location: Moon, Dark Side
Posts: 1,095
| | | re: Make file upload as fast as download, (no n00b) Quote:
Originally Posted by Atli 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.
|  | Expert | | Join Date: Dec 2007 Location: Moon, Dark Side
Posts: 1,095
| | | 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: -
-
<?php
-
/**
-
* Test file upload and download speed, manually timeing it
-
*
-
*/
-
$destination = "/tmp/testFile.txt"; // where the file should be saved (apache must have access)
-
$fileUploaded = false; // flag to display download button.
-
-
// FIRST PAGE
-
if($_POST['submit'])
-
{
-
move_uploaded_file($_FILES['testFile']['tmp_name'],$destination);
-
$uploadTook = round(microtime(true) - ($_POST['startUploadTS']/1000),5);
-
$fileUploaded = true;
-
}
-
-
// SECOND PAGE
-
if($_POST['downloadFile'])
-
{
-
if(file_exists("/tmp/testFile.txt"))
-
{
-
// commented out headers to output file to screen and not wait to open/save dialogue box. uncomment to see dialogue box.
-
// header('Content-Description: File Transfer');
-
// header('Content-Type: application/octet-stream');
-
// header('Content-Disposition: attachment; filename=test.txt');
-
// header('Content-Transfer-Encoding: binary');
-
// header('Expires: 0');
-
// header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
-
// header('Pragma: public');
-
// header('Content-Length: ' . filesize($destination));
-
$begin = microtime(true);
-
ob_clean();
-
flush();
-
echo file_get_contents($destination);
-
echo "<hr><br><br>Download took: ", round((microtime(true) - $begin),5), " MS";
-
exit();
-
}
-
}
-
-
?>
-
<html>
-
<body>
-
<?php if ($fileUploaded) {?>
-
-
<form name="global" id="global" action="" method="post" enctype="multipart/form-data">
-
<input type="submit" name="downloadFile" value="Click Here To Download File"><br />
-
Upload Took: <?php echo $uploadTook ?> MS
-
</form>
-
-
<?php } else { ?>
-
-
<form name="global" id="global" action="" method="post" enctype="multipart/form-data">
-
<input type="hidden" name="startUploadTS" id="startTime" value="" />
-
<input type="file" name="testFile" id="testFile" />
-
<input type="submit" name="submit" value="Upload ^" onclick="document.getElementById('startTime').value = new Date().valueOf()" />
-
</form>
-
-
<?php } ?>
-
</body>
-
</html>
-
-
Feel free to run this on your *test* (not live) server as well.
|  | | | | /bytes/about
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 226,449 network members.
|