Skip to content

Differences between ATTR_TIMEOUT and SQLSRV_ATTR_QUERY_TIMEOUT? #1100

@gjdanis

Description

@gjdanis

PHP Driver version or file name

5.8

SQL Server version

Microsoft SQL Server 2017 (RTM-CU8) (KB4338363) - 14.0.3029.16 (X64) Jun 13 2018 13:35:56 Copyright (C) 2017 Microsoft Corporation Developer Edition (64-bit) on Linux (Ubuntu 16.04.4 LTS)

Client operating system

Windows 10 enterprise

PHP version

PHP 7.2.9 (cli) (built: Aug 22 2018 18:31:06) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
with Zend OPcache v7.2.9, Copyright (c) 1999-2018, by Zend Technologies
with Xdebug v2.6.0, Copyright (c) 2002-2018, by Derick Rethans

Microsoft ODBC Driver version

Table schema

CREATE DATABASE test

Problem description

It looks like ATTR_TIMEOUT and SQLSRV_ATTR_QUERY_TIMEOUT don't exhibit the same behavior. Setting SQLSRV_ATTR_QUERY_TIMEOUT ensures your query doesn't last more than a certain number of seconds. Setting ATTR_TIMEOUT doesn't seem to have this effect.

Expected behavior and actual behavior

ATTR_TIMEOUT should have the same behavior as SQLSRV_ATTR_QUERY_TIMEOUT.

Repro code or steps to reproduce

    $username = ...
    $password = ...

    $pdo = new \PDO('sqlsrv:Server=localhost; Database=test', $username, $password);
    $pdo->setAttribute(\PDO::ATTR_TIMEOUT, 1);

    $start = time_ms(true);
    try {
      $pdo->exec("WAITFOR DELAY '00:00:30'");
    } catch (\Throwable $th) {
      echo $th->getMessage() . PHP_EOL;
    } finally {
      $elapsed = time_ms(true) - $start;
      echo $elapsed . PHP_EOL;
    }

    $pdo = new \PDO('sqlsrv:Server=localhost; Database=test', $username, $password);
    $pdo->setAttribute(\PDO::SQLSRV_ATTR_QUERY_TIMEOUT, 1);

    $start = time_ms(true);
    try {
      $pdo->exec("WAITFOR DELAY '00:00:30'");
    } catch (\Throwable $th) {
      echo $th->getMessage() . PHP_EOL;
    } finally {
      $elapsed = time_ms(true) - $start;
      echo $elapsed . PHP_EOL;
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions