D T
D T

Reputation: 3756

Why can't increase Connect Timeout?

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? I using xampp 3.2.2, Database Postgresql 9.2 I test at local, not exist Anti Virus.

Upvotes: 1

Views: 887

Answers (4)

Peter Haberkorn
Peter Haberkorn

Reputation: 259

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.

Upvotes: 3

Narf
Narf

Reputation: 14752

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.

Upvotes: 9

Er Nilay Parekh
Er Nilay Parekh

Reputation: 587

Just put

ini_set("default_socket_timeout", 50);
before your PDO() connect string.

Upvotes: 1

AZinkey
AZinkey

Reputation: 5329

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

Upvotes: 1

Related Questions