如何在PHP中改善MySQL连接时间?

As testing performances on APIs, I found that 30% of response time for APIs are spent on connecting to MySQL. (Min. 500ms - Max. 600ms)

I assumed that it was because of MySQL settings, so I changed various settings to improve the connection time, but without luck.

I did not use any framework to test it. I wanted to compare with other languages, so I tested Python. Its result was around 50ms which is a lot better than 500-600ms of PHP.

What would be the reasons for such delay on PHP, but not on Python?

Here is the environment under which I tested:

  • php version : 7.1.9-1+0~20170902060604.8+jessie~1.gbpebe5d6
  • python version : 3.6.2
  • platform : Linux(Ubuntu)
  • mysql version : 5.7.2

Depending upon your use case, you may be able to dramatically increase your response time by using persistent connections.