Measuring the process time after clicking a link
I want to download a document from a server. Creating开发者_如何学C the document in the server takes some time, and I need to measure the time it takes from clicking the link to the end of the download process at client side. (or to the beginning of the download?)
Any way for this?
Thanks
Re your update in the comment:
When the user clicks the link, I want to inform the user that the request is being processed; something like "Please Wait". And when the server side process is completed and the download starts, the "Please Wait" text should be invisible.
As I said in the comments, this is not as easy to do for a document download as it is for a web page.
A way that would be guaranteed to work is loading the document into an iframe (so that the whole page doesn't freeze), and polling the document's production status from the outside document using Ajax. That could be achieved half-way easily if you can make your document generating PHP script write the production status ("working" / "finished" or even a percentage value) into a text file that the Ajax call can query frequently. You would name the text file by a unique random key that would have to be created in the page containing the download link, and passed to the script generating the document.
You might be able, as you say, to query the IFrame's status somehow but I wouldn't know a defined way to do this: There will be no onload
event (because no document will be loaded - once the browser receives the information to expect a file download, it will pop up the "Save as" dialog and leave the IFrame's context completely). However it could be that the IFrame's src
property is set only when the document is produced (i.e. when the content-type and other headers have been sent) - you would have to try.
I use Google Chrome's developer tools to track time. It differentiates between the time taken to connect to the server and the time to download.
To use, Ctrl+Shift+I and then go to the resources tab. Access your page and you should find as you click around, it tells you all the times you might need.
This will tell you from the clients point of view. If you want to know what is taking the server so long to produce the document, you'd need to explore that from your Server-side coding point of view :)
精彩评论