best way to measure (and refine) performance with PHP?

后端 未结 6 1858
名媛妹妹
名媛妹妹 2021-02-09 02:20

A site I am working with is starting to get a little sluggish, and I would like to refine it. I think the problem is with the PHP, but I can\'t be sure. How can I see how long f

6条回答
  •  一个人的身影
    2021-02-09 02:42

    • You can also make it manually, by recording microtime() value in various places, like this:

      
      

    and then visualize it

    nameso fardeltaper cent";
      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 "$name$sofar$delta$percent";
        $prev=$value;
      }
        echo "";
    }
    ?>
    

    an IP address check implies that we are doing this profiling on the working site

    • Though I doubt it's PHP itself. Most likely it's database. So, pay most attention to query execution timing.

    • however, a "site" term is very broad. It includes also JS, CSS, images and stuff. So, I'd suggest to start form FirebFug's Net page to see what part of whole page takes more time.

    Of course, refining can be done only after analysis of profiling results, and cannot be advised here without it.

提交回复
热议问题