What are some good PHP performance tips?

前端 未结 13 1720
挽巷
挽巷 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:26

    Use single rather than double quotes wherever possible. (Or even a variable, as silly as it sounds) Abuse the PHP associative arrays, they are hash tables and are really fast for any kind of look up.

    However, don't focus so much on low level performance. Tasks you perform in PHP are normally very simple. They are typically often repeated. What this means is the real focus you should have for speed are are around the edges of PHP.

    Focus on speed between PHP and your Database. Focus on the size of markup on the way out. Focus on cache.

    It is VERY rare that you'll see any kind of win out of optimization of the code itself. At least on the scale of picking one function over another. Clearly you want to avoid redundant or useless repetition. But aside from that you shouldn't really worry.

    0 讨论(0)
提交回复
热议问题