Benchmarking PHP page load times

前端 未结 10 2084
借酒劲吻你
借酒劲吻你 2021-01-31 10:56

How could I measure the time taken to load a page (with various different PHP statements)?

Somewhat like the stats available here - http://talks.php.net/show/drupal08/24

10条回答
  •  梦谈多话
    2021-01-31 11:21

    You say you want to measure "Page load times" which is completely different from

    1. the time it takes to generate the page (as measured by an internal timer in your PHP code)

    2. and offload it from the server (which is measured by ab)

    A page load time should include the time taken to parse the HTML and to make subsequent requests to the server to fetch all related content (javascript files, css files, images etc).

    Measuring this is actually quite difficult. To do it properly, you need to push all the logic client side - drop a timestamped javascript cookie when the user clicks on a link or submits a form, then in the subsequent page, using the onload method (which fires after everything has loaded) compared this time with the current time. You then need a method of reporting this metric back to the server - you can use an Ajax request, or store the time in another cookie to be presented in the subsequent request.

    Note that the files required by each client will depend on the current state of the browser side cache.

    If you can isolate click streams from your logs, then you can get a good approximation by checking the interval between a request for a text/html content type and the last consecutive request for content type other than text/html. But your stats will get skewed if users interact usnig more than one browser window simultaeneously.

提交回复
热议问题