Postgresql slow simple queries using PHP PDO/driver

Viewed 103

Having a hard time understanding why PostgreSQL from google cloud services is taking > 400 ms for any simple query (~4-row table) from my PHP code using PDO or pg driver. IP ping averages around 60 ms so it seems it's not a distance problem. Using both PGAdmin and PHP yield around a 400+ ms response time.

$before_conn1 = microtime(true);
$result = pg_query($connector->conn(),$query);
$after_conn1 = microtime(true);

$test = $after_conn1 - $before_conn1;
echo $test;return;

// response time 0.46275 unix timestamp

query looks like this:

SELECT id,clearance from table

literally the table has 4 rows and 2 columns.

1 Answers

Seems the lag was caused by the PDO driver. I'm not sure exactly why but ended up using pg_query for a single query and pg_send_query for batch selects with the asynchronous response which worked really well! Hope this helps others.

Related