Slow connection PHP PDO Postgres but not MySQL

Viewed 119

here's the thing - PDO Postgresql connections seem to be really slow on my setup. I have the same database in both MySQL & Postgresql. I measured a few scenarios: PDO connection time only, PDO connection + a simple SELECT and lastly the same SELECT using pg_connect + pg_query. The pg_ methods (~25k req/s), the PDO MySQL SELECT (~12k req/s) and the PDO MySQL connection (~18k req/s) seem okay, but PDO Postgres connection (~900 req/s) and connection + SELECT (~800 req/s) seem incomparably slower. Here are my code snippets:

MySQL

$db = "mysql:host=$host;dbname=ihmj";
$dbh = new PDO($db, $user, $password);

// connection only
return "";

// + SELECT
return json_encode($dbh->query('SELECT * from comment')->fetchAll());
Postgresql

// the only difference is the db driver
$db = "pgsql:host=$host;dbname=ihmj";
$dbh = new PDO($db, $user, $password);

// connection only
return "";

// + SELECT
return json_encode($dbh->query('SELECT * from comment')->fetchAll());
Postgresql pg_functions

$conn = pg_pconnect(" host = $host dbname = $name user = $user password = $password ");
$result = pg_query($conn, "SELECT * from comment;");

return json_encode(pg_fetch_assoc($result));

I'm using PHP 8.0.1. Any help is appreciated.

0 Answers
Related