Monday, October 16, 2017

Why can't increase Connect Timeout?

Leave a Comment

This is my setting:

$DBH = new PDO(         "pgsql:host=$host;dbname=$dbname",          $username,          $password,         array(             PDO::ATTR_TIMEOUT => 60,             PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION         )     ); 

It is time out after 20s. But If i set PDO::ATTR_TIMEOUT => 5, It will time out after 5s.

Why can't increase Connect Timeout?

4 Answers

Answers 1

PDO::ATTR_TIMEOUT and the default_socket_timeout INI setting are the only values you can change from PHP, but a TCP connection can be affected by a lot of factors.

On the client side, a firewall or the OS itself may also apply timeout limits.
In transit, any of the intermediate peers (your router, ISPs) can also drop connections based on various rules.

But most importantly (i.e. more likely in your case), the connection involves two parties and the PostgreSQL server also has its own timeout settings - tcp_keepalives_idle, tcp_keepalives_interval, tcp_keepalives_count and authentication_timeout.

Reference: https://www.postgresql.org/docs/current/static/runtime-config-connection.html

Exactly what affects you is impossible to guess, and you'd possibly need to change more than one setting. Check for each of the above that you can.

Answers 2

execute PDO::errorInfo after the block if you want to find out why its timeouting

http://php.net/manual/de/pdo.errorinfo.php

and the timeout ist maybe from the other side why should the script waiting 60 sec when the db response timeout after 20 sec.

Answers 3

use ini_set("default_socket_timeout", 60); before connect

Answers 4

Just put

ini_set("default_socket_timeout", 50); before your PDO() connect string. 
If You Enjoyed This, Take 5 Seconds To Share It

0 comments:

Post a Comment