Justin
Justin

Reputation: 45330

Retrieve how long it takes to establish a connection with PHP mysqli_real_connect()

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.

Upvotes: 0

Views: 765

Answers (1)

djot
djot

Reputation: 2947

$start_time = microtime(TRUE);

// do anything ... mysqli

$stop_time = microtime(TRUE);

$duration = $stop_time - $start_time;

var_dump($duration);

Upvotes: 3

Related Questions