Retrieve how long it takes to establish a connecti

2019-06-13 21:11发布

问题:

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:

$start_time = microtime(TRUE);

// do anything ... mysqli

$stop_time = microtime(TRUE);

$duration = $stop_time - $start_time;

var_dump($duration);