TCP保持活动PDO连接参数 [英] TCP Keep-Alive PDO Connection Parameter

查看:137
本文介绍了TCP保持活动PDO连接参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

PHP的PDO(或相应的 PostgreSQL驱动程序)是否具有连接配置选项,用于启用TCP保持活动探测类似于JDBC ?

Does PHP's PDO (or it's respective PostgreSQL driver) have a connection configuration option for enabling a TCP keep-alive probe like JDBC?

我遇到一个问题,我们正在通过NAT建立连接,该连接在5分钟后会断开连接(我无法更改),并且我们在外部Postgres实例上运行的查询花费的时间超过5分钟的时间,导致我们的客户端永远不会收到来自Postgres实例的响应,并最终超时.

I'm experiencing an issue where we're making a connection through a NAT which drops connections after 5 minutes (I can't change this), and the query we're running on an external Postgres instance takes longer than 5 minutes to run, causing our client to never receive a response from the Postgres instance and eventually time out.

推荐答案

PDO PostgreSQL驱动程序建立在libpq客户端库的顶部.该驱动程序允许以键/值对的形式在DSN中传递特定的libpq连接选项,其中包括TCP keepalive选项.

The PDO PostgreSQL driver is built on top of the libpq client library. The driver allows to pass specific libpq connections options in the DSN in the form of key/values pairs, among which the TCP keepalives options.

来自 PostgreSQL文档:

保持活力

控制是否使用客户端TCP keepalive.默认值为1,表示打开,但是如果为0,则可以将其更改为0,表示关闭. 不需要keepalives.连接将忽略此参数 通过Unix域套接字制作.

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

控制不活动的秒数,在此之后TCP应该向服务器发送一个保持活动消息.零使用值 系统默认值.对于通过进行的连接,将忽略此参数 Unix域套接字,或者是否禁用了keepalive.只有 在使用TCP_KEEPIDLE或TCP_KEEPALIVE套接字的系统上受支持 该选项可用,并且在Windows上;在其他系统上,它没有 效果.

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

控制秒数,在该秒数之后,应重新传输服务器未确认的TCP Keepalive消息.一种 零值使用系统默认值.该参数被忽略 通过Unix域套接字建立的连接,或者如果keepalive是 禁用的.仅在TCP_KEEPINTVL的系统上支持 套接字选项可用,并且在Windows上;在其他系统上,它具有 没有效果.

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');
?>

这篇关于TCP保持活动PDO连接参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆