TCP Keep-Alive PDO 连接参数
TCP Keep-Alive PDO Connection Parameter
是否 PHP 的 PDO(或者它各自的 PostgreSQL driver) have a connection configuration option for enabling a TCP keep-alive probe like JDBC?
我遇到了一个问题,我们通过 NAT 建立连接,5 分钟后连接断开(我无法更改),我们正在 运行 查询外部 Postgres 实例需要超过 5 分钟才能到达 运行,导致我们的客户端永远不会收到来自 Postgres 实例的响应并最终超时。
您可以更新内核保活时间:
echo 250 > /proc/sys/net/ipv4/tcp_keepalive_time
(感谢 Chris Merrick)
PDO PostgreSQL 驱动程序建立在 libpq 客户端库之上。驱动程序允许以 key/values 对的形式在 DSN 中传递特定的 libpq 连接选项,其中包括 TCP keepalives 选项。
keepalives
Controls whether client-side TCP keepalives are used. The default value is 1, meaning on, but you can change this to 0, meaning off, if
keepalives are not wanted. This parameter is ignored for connections
made via a Unix-domain socket.
keepalives_idle
Controls the number of seconds of inactivity after which TCP should send a keepalive message to the server. A value of zero uses
the system default. This parameter is ignored for connections made via
a Unix-domain socket, or if keepalives are disabled. It is only
supported on systems where the TCP_KEEPIDLE or TCP_KEEPALIVE socket
option is available, and on Windows; on other systems, it has no
effect.
keepalives_interval
Controls the number of seconds after which a TCP keepalive message that is not acknowledged by the server should be retransmitted. A
value of zero uses the system default. This parameter is ignored for
connections made via a Unix-domain socket, or if keepalives are
disabled. It is only supported on systems where the TCP_KEEPINTVL
socket option is available, and on Windows; on other systems, it has
no effect.
示例:
<?
$db = new PDO('pgsql:dbname=mydb;host=localhost;user=myuser;password=mypass;keepalives_idle=60');
?>
是否 PHP 的 PDO(或者它各自的 PostgreSQL driver) have a connection configuration option for enabling a TCP keep-alive probe like JDBC?
我遇到了一个问题,我们通过 NAT 建立连接,5 分钟后连接断开(我无法更改),我们正在 运行 查询外部 Postgres 实例需要超过 5 分钟才能到达 运行,导致我们的客户端永远不会收到来自 Postgres 实例的响应并最终超时。
您可以更新内核保活时间:
echo 250 > /proc/sys/net/ipv4/tcp_keepalive_time
(感谢 Chris Merrick)
PDO PostgreSQL 驱动程序建立在 libpq 客户端库之上。驱动程序允许以 key/values 对的形式在 DSN 中传递特定的 libpq 连接选项,其中包括 TCP keepalives 选项。
keepalives
Controls whether client-side TCP keepalives are used. The default value is 1, meaning on, but you can change this to 0, meaning off, if keepalives are not wanted. This parameter is ignored for connections made via a Unix-domain socket.
keepalives_idle
Controls the number of seconds of inactivity after which TCP should send a keepalive message to the server. A value of zero uses the system default. This parameter is ignored for connections made via a Unix-domain socket, or if keepalives are disabled. It is only supported on systems where the TCP_KEEPIDLE or TCP_KEEPALIVE socket option is available, and on Windows; on other systems, it has no effect.
keepalives_interval
Controls the number of seconds after which a TCP keepalive message that is not acknowledged by the server should be retransmitted. A value of zero uses the system default. This parameter is ignored for connections made via a Unix-domain socket, or if keepalives are disabled. It is only supported on systems where the TCP_KEEPINTVL socket option is available, and on Windows; on other systems, it has no effect.
示例:
<?
$db = new PDO('pgsql:dbname=mydb;host=localhost;user=myuser;password=mypass;keepalives_idle=60');
?>