What are some good PHP performance tips?

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

    It's obvious, but creating objects is also costly, so for ex. if you need a timestamp doing a time() is double faster than doing a date_create()->getTimestamp.

    for ($a=1;$a<1000000;$a++) {
      $e = time(); // In my tests about 2x faster than:
      //$e = date_create()->getTimestamp();
    }
    

提交回复
热议问题