How can I measure the time it takes a file to upload to a PHP script?

Posted by Gustav Bertram on Stack Overflow See other posts from Stack Overflow or by Gustav Bertram
Published on 2011-11-18T10:57:29Z Indexed on 2011/11/20 1:50 UTC
Read the original article Hit count: 158

Filed under:
|
|

I am trying to measure the time a script takes to upload a file to a PHP script, inside the receiving script. Here's a short example:

<form action="#" enctype="multipart/form-data" method="post">
    Upload:
    <input type="file" name="datafile" size="40">
    <input type="submit" value="Send">
</form>
<?php

$upload_time = time() - $_SERVER['REQUEST_TIME'];
echo $upload_time . " seconds.";

I've submitted 4MB, 25MB, 100MB and 1.4GB files. They took anything from a fraction of a second, to almost a minute, yet the script above always yielded 0 seconds.

NOTE: I know that this is a duplicate question, but the accepted answer on the other question did not work for me (at least, initially): Detect how long it takes for a file to upload (PHP)

I've tried it using PHP 5.3.3 with Apache 2.2.16 on Ubuntu 10.4.

UPDATE:

I've discovered that both the Apache header and Ajax solutions work. In fact, the solution on the duplicate question also works.

The critical element to making these solutions work is to ensure that the following values in the php.ini are sufficiently high:

memory_limit = 1000M
upload_max_filesize = 1000M
post_max_size = 1000M

I am accepting the Apache header solution, since it only uses PHP.

© Stack Overflow or respective owner

Related posts about php

Related posts about apache