I'm using php7.4-fpm, connecting to PostgreSQL 12.3 (Ubuntu 12.3-1.pgdg18.04+1). When I use pgadmin4 the query is executed in 129msec and results instantly on the screen, the same query over php about 4 seconds. What I'm doing wrong? My con str:
$conStr = sprintf("pgsql:host=%s;port=%d;dbname=%s;user=%s;password=%s",
$params['host'],
$params['port'],
$params['database'],
$params['user'],
$params['password']
);
$pdo = new PDO($conStr);
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$pdo->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_OBJ);
Here is a sample query, but it doesn't make any difference what query I run, but there is a noticeable difference when the query is run in PDO compared to when it is run in pgadmin:
SELECT job_number, customer, (SELECT to_jsonb(other_names) FROM companies WHERE name=customer) AS customer_other_names, description, customer_order_number, delivery_date, delivery_address, price, completed_date FROM jobs;
Edit 2020-07-09: Found that HTTP2 protocol was the cause of slow connection, I discovered by accident, having some trouble passing data to php. Looking for solutions while reverted to HTTP1.1
Edit 2020-07-11 It seems that HTTP2 is not the reason for it, it was just a bit faster after restarting Apache2 service, but very soon back to "normal", slow. I dont get it, the tables contain under 100 records max, only few columns and the queries are not slow under pgsql. I'm certain there is something in php, just can't find it.