phpmysqlmysql-connect

How to improve MySQL connection time in PHP?


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:


Solution

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