how to measure time to upload a file (from browser to server) in php from the server point of view?

StackOverflow https://stackoverflow.com/questions/8559786

  •  21-03-2021
  •  | 
  •  

Question

Does php provide api to check multipart/form-data upload rate , or total duration ?

I also want to know how does PHP knows about various timeout events from IIS and php.ini settings ?

Was it helpful?

Solution

There's a value in $_SERVER you can check to find out when the request was initiated. From the PHP manual:

'REQUEST_TIME' The timestamp of the start of the request. Available since PHP 5.1.0. It is float with microseconds since PHP 5.4.0.

So you can compare $_SERVER ['REQUEST_TIME'] against the current time() with the proviso that you're limited to a resolution of 1 second until PHP 5.4 becomes widespread.

OTHER TIPS

I don't think so - the upload is finished by the time PHP can do anything to it, i.e apache gets the upload then, when finished, hands it to PHP - your script won't even run before that, so unless there is a way to get this information retrospectively I don't think you can get it from PHP alone.

The usual way to get this data is client-side using flash or javascript or both. For example, uploadify or swfupload are both great flash uploaders that provide client-side filesize limiting and upload progress indication to the user.

It would be so much easier if file uploading, progress indication and filesize limiting could be done by the browser itself :(

Reference:

http://www.uploadify.com/demos/

http://swfupload.org/

For the first question, I believe you can use the $_SERVER['REQUEST_TIME'] variable to do the calculation yourself, together with time().

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top