Benchmarking PHP page load times

前端 未结 10 2085
借酒劲吻你
借酒劲吻你 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:37

    There are many ways to do this. I've personally been a fan of using microtime in the following way:

    // Start of code
    $time = microtime(true); // Gets microseconds
    
    // Rest of code
    
    // End of code
    echo "Time Elapsed: ".(microtime(true) - $time)."s";
    

    That will give you microsecond accuracy.

    If you are writing command-line scripts (like Facebook puzzles), you can use just time.

    time php dancebattle.php ~/input.dat
    Win
    
    real    0m0.152s
    user    0m0.142s
    sys     0m0.012s
    

    I forgot about the method of monitoring page load times (from a browser). You can use the NET tab from Firebug (for Firefox) to do just that. It will let you watch the various file loads (AJAX, JS, CSS, Images, etc.).

提交回复
热议问题