duanjiongzhen2523 2014-04-11 21:12
浏览 304
已采纳

什么决定了PDO :: ATTR_TIMEOUT如何与ODBC连接一起工作?

The documentation for ATTR_TIMEOUT says:

Specifies the timeout duration in seconds. Not all drivers support this option, and it's meaning may differ from driver to driver. For example, sqlite will wait for up to this time value before giving up on obtaining an writable lock, but other drivers may interpret this as a connect or a read timeout interval.

I am using an ODBC connection via unixODBC to a closed-source database called Vertica, and I am not seeing the proper connection timeout behavior when I connect via:

$this->conn = new PDO($dsn, $user, $password,
                      array(PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
                            PDO::ATTR_TIMEOUT => 2));   // timeout in 2 seconds

Is that behavior provided by the PDO PHP class, or unixODBC, or the Vertica ODBC driver itself? Trying to figure out where to start debugging.

  • 写回答

1条回答 默认 最新

  • dqxmf02844 2014-04-23 23:44
    关注

    I ended up solving this simply by attempting to open a TCP connection to vertica with a timeout (on the correct port), and immediately closing on a successful connection. While this does not guarantee that I am actually talking to a healthy Vertica database, it is sufficient for my own use case.

    Something like this seems to be working OK:

    protected function isAlive() {
        $socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
        socket_set_nonblock($socket);
        for ($i=0; $i<5; $i++) {
            if(!@socket_connect($socket, $this->host, $this->port)) {
                usleep(100000);                 // sleep for 0.1 seconds
            } else {
                return true;
            }
        }
        return false;
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器