Benchmarking PHP page load times

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

    1. method one: use xdebug.
    2. method two: Put these statements all around your your scripts

      $TIMER['label']=microtime(1);
      /* some code */
      $TIMER['sql1_before']=microtime(1);
      a/* some code */
      $TIMER['sql1_after']=microtime(1);
      /* some code */

    and then output it, with code like this:

      echo "";
      reset($TIMER);
      $start=$prev=current($TIMER);
      $total=end($TIMER)-$start;
      foreach($TIMER as $name => $value) {
        $sofar=round($value-$start,3);
        $delta=round($value-$prev,3);
        $percent=round($delta/$total*100);
        echo "";
        $prev=$value;
      }
        echo "
    nameso fardeltaper cent
    $name$sofar$delta$percent
    ";

    Thus, you'll get tetailed report on how your code goes. this action called profiling and take most important place in the optimization process.

提交回复
热议问题