Skip to content

ext/pdo_odbc: add support for PDO::ATTR_TIMEOUT - #24375

Draft
NattyNarwhal wants to merge 3 commits into
php:masterfrom
NattyNarwhal:pdo-odbc-timeout
Draft

NattyNarwhal wants to merge 3 commits into
php:masterfrom
NattyNarwhal:pdo-odbc-timeout

Conversation

@NattyNarwhal

Copy link
Copy Markdown
Member

From the main commit:

ODBC has both a connection timeout for the connection level and a query
timeout at the statement level. Annoyingly, these are somewhat poorly
defined. The connection timeout, for instance, can be defined as either
a login/connection setup timeout, or as a generic "any action" timeout,
and if the latter, the query timeout may not necessarily be implemented.

Accordingly, because we have no way to differentiate, we have to set
both, and have special handling for the initial connection, as the
setAttribute call won't handle early enough if it only handles initial
connection timeouts. This means changing it after for a connection isn't
relevant for existing statements that have already been constructed;
this commit doesn't add a way to change it for a statement after
changing it on the connection (be it via setAttribute on the statement,
or somehow changing statements from the connection setAttribute).

Also annoying is the difference in behaviour between drivers when a
timeout happens. For example, SQL Server has a query timeout which just
gracefully ends the current query, but Db2i only has a connection
timeout which puts the whole connection into an invalid state (but at
least it should fail a liveness check for a persistent connection). We
don't have much control over this unfortunately.

In the future, we should consider clarifying the PDO timeout attribute
behaviour's on statements vs. connections, or make them separate
attributes, like how PDO_DBLIB has.

May need some refinement for i.e. statement timeout stuff, but I suspect anything needing a new attribute will need the RFC process.

It's not exhaustive, better to have nop attributes be handled by default
ODBC has both a connection timeout for the connection level and a query
timeout at the statement level. Annoyingly, these are somewhat poorly
defined. The connection timeout, for instance, can be defined as either
a login/connection setup timeout, or as a generic "any action" timeout,
and if the latter, the query timeout may not necessarily be implemented.

Accordingly, because we have no way to differentiate, we have to set
both, and have special handling for the initial connection, as the
setAttribute call won't handle early enough if it only handles initial
connection timeouts. This means changing it after for a connection isn't
relevant for existing statements that have already been constructed;
this commit doesn't add a way to change it for a statement after
changing it on the connection (be it via setAttribute on the statement,
or somehow changing statements from the connection setAttribute).

Also annoying is the difference in behaviour between drivers when a
timeout happens. For example, SQL Server has a query timeout which just
gracefully ends the current query, but Db2i only has a connection
timeout which puts the whole connection into an invalid state (but at
least it should fail a liveness check for a persistent connection). We
don't have much control over this unfortunately.

In the future, we should consider clarifying the PDO timeout attribute
behaviour's on statements vs. connections, or make them separate
attributes, like how PDO_DBLIB has.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant