Skip to content

ext/pdo_dblib: Added dblib_handle_check_liveness handler#21681

Closed
freddy77 wants to merge 1 commit intophp:masterfrom
freddy77:master
Closed

ext/pdo_dblib: Added dblib_handle_check_liveness handler#21681
freddy77 wants to merge 1 commit intophp:masterfrom
freddy77:master

Conversation

@freddy77
Copy link
Copy Markdown
Contributor

@freddy77 freddy77 commented Apr 9, 2026

In case of persistent connection it was not checked if the connection was still alive always assuming it was. If the connection was broken this caused PHP to reuse the broken connection over and over.
dbdead function is supported by all dblib implementation (MS, Sybase, FreeTDS).
Change tested manually, see FreeTDS/freetds#711 (comment)

Feel free to update comment or code.
As the comment above I didn't test the change myself.
I don't see an easy way to write a test for this change.

Copy link
Copy Markdown
Member

@SakiTakamachi SakiTakamachi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the delayed review.
This makes a lot of sense.

Regarding tests, I’ve done something similar in pdo_firebird before. In that case, I wrote a test to ensure that check_liveness is not broken and that the same connection is reused when using persistent connections.

https://github.com/php/php-src/blob/master/ext/pdo_firebird/tests/persistent_connect.phpt

For SQL Server or Sybase, you can obtain the connection ID with SELECT @@SPID, so it should be possible to create a test similar to the one for Firebird.

If this would be a burden for you, I can also add the test myself.

Anyway, thank you for this change!

Comment thread ext/pdo_dblib/dblib_driver.c Outdated
In case of persistent connection it was not checked if the
connection was still alive always assuming it was.
If the connection was broken this caused PHP to reuse the
broken connection over and over.
dbdead function is supported by all dblib implementation
(MS, Sybase, FreeTDS).
Change tested manually, see
FreeTDS/freetds#711 (comment)

Signed-off-by: Frediano Ziglio <freddy77@gmail.com>
Copy link
Copy Markdown
Member

@SakiTakamachi SakiTakamachi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Although I created a test, it turned out to be largely meaningless for SQL Server and Sybase. I’ve decided the test is unnecessary and will proceed to merge as is.
Thank you!

@SakiTakamachi SakiTakamachi changed the title pdo_dblib: Do not reuse dead connections ext/pdo_dblib: Added dblib_handle_check_liveness handler May 3, 2026
SakiTakamachi added a commit that referenced this pull request May 3, 2026
@freddy77
Copy link
Copy Markdown
Contributor Author

freddy77 commented May 4, 2026

Thank you.

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.

2 participants