TCP PDU-Alive PDO Connection Parameter

Does PHP PDO (or the corresponding PostgreSQL driver ) provide a connection configuration parameter to enable the keep-alive TCP probe as JDBC ?

I had a problem when we connect through NAT, which disconnects after 5 minutes (I can’t change this), and the request that we run on an external Postgres instance takes more than 5 minutes to start, as a result of which our client never will receive a response from the Postgres instance and, ultimately, a timeout.

+1
source share
2 answers

The PostgreSQL PDO driver is built on top of the libpq client library. The driver allows you to transfer certain parameters of libpq connections to DSN in the form of key / value pairs, including TCP keepalives parameters.

From a PostgreSQL doc :

activity support

Controls the use of TCP client keepalives. The default value is 1, that is, the value, but you can change it to 0, which means "turn off" if keepalives are not needed. This parameter is ignored for connections made through a Unix domain socket.

keepalives_idle

, TCP keepalive . . , Unix- keepalives . , TCP_KEEPIDLE TCP_KEEPALIVE Windows; .

keepalives_interval

, TCP, , . . , Unix-, keepalives . , TCP_KEEPINTVL , Windows; .

:

<?
$db = new PDO('pgsql:dbname=mydb;host=localhost;user=myuser;password=mypass;keepalives_idle=60');
?>
+3

keepalive :

echo 250 > /proc/sys/net/ipv4/tcp_keepalive_time

( )

+2

Source: https://habr.com/ru/post/1016058/


All Articles