What are some good PHP performance tips?

前端 未结 13 1718
挽巷
挽巷 2020-12-24 07:55

I\'ve heard of some performance tips for PHP such as using strtr() over str_replace() over preg_replace() depending on the situation.

13条回答
  •  醉梦人生
    2020-12-24 08:01

    You must measure before you optimize. Without measurements, you cannot have goals. Without goals, you are wasting your time.

    If you discover that your webpage takes 250ms to render, is that fast enough? If not, how fast should it be? It won't get down to zero. Do you need it to be 200ms?

    Use a tool like XDebug (http://www.xdebug.org/) to determine where the hotspots in your code are. Chances are you will find that your app is taking 80% of its time accessing the database. If your app is taking 200ms to get data from the database, and .01ms in str_replace calls, then the speedups of going to strtr, or of using echo instead of print are so small as to be irrelevant.

    The dream of being able to use strtr instead of str_replace and get noticeable, measurable speedups is a fantasy.

提交回复
热议问题