Retrieve how long it takes to establish a connecti

2019-06-13 20:36发布

I am trying to find the bottleneck for an internal PHP application. I can only get around 10 req/sec before requests start taking 5 or more seconds to complete. The CPU load on the server is nothing, vmstat does not show any I/O wait or swap. I have a strong suspicion it is the connection to an external MySQL server causing the slow down. I am using:

mysqli_real_connect(...)

Is there a way to time how long it takes to connect, and log it somewhere, so I can view how long the actual handshake and connection to the MySQL server is taking.

1条回答
干净又极端
2楼-- · 2019-06-13 20:53
$start_time = microtime(TRUE);

// do anything ... mysqli

$stop_time = microtime(TRUE);

$duration = $stop_time - $start_time;

var_dump($duration);
查看更多
登录 后发表回答