-
Notifications
You must be signed in to change notification settings - Fork 7.9k
mysqli->ping() throws an exception if the connection is broken #11897
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Whatever error is thrown is controlled by $mysqli->report_mode with option |
I don't think it makes sense for this function to throw exceptions, because it is usually used to check if a reconnection to the database is needed and it is therefore expected to fail some of the times. The fact that since PHP 8.1 it throws an exception makes all examples in the documentation non-working with the default mysqli reporting options. |
@TheNewHEROBRINEX |
Yeah, I guess it makes sense, but I wonder if it's even possible. I will have to look at it more closely. I am not very familiar with this method or how it should actually work. |
|
Thanks for the MySQL version info. I've got it down to the point where the exception message is from mysqlnd, not mysqli, but I don't see much difference between 8.1 and 7.4 in the code around it. It is not yet possible to determine which ext is the cause, as it is quite possible that mysqli is not catching the exception, etc., but I will continue to investigate. If anything turns up, I'll comment again. |
It is a simply problem with the reporting options only. I can fix it so that no exceptions are thrown. |
What do you intend to do? Make $mysqli->ping() behave like mysqli reporting is set MYSQLI_REPORT_OFF, regardless of its current value? |
Yes, that is exactly right. |
That would be acceptable for me but I think the best thing to do would be to exempt $mysqli->ping() from throwing exceptions only if the error is that the connection has been broken but to make it still throw exceptions for other errors.
But there is a problem with this: the first time $mysqli->ping() fails, the error is erroneously reported as "Malformed packet" while it doesn't make sense since no packet has been actually received from the server since the connection is broken. If you try to ping the server from the second time on the correct error ("MySQL server has gone away") will be reported. |
I think the problem is that php-src/ext/mysqlnd/mysqlnd_wireprotocol.c Line 297 in b275e13
but then mysqlnd_protocol::send_command_handle_OK doesn't check for it and assumes the problem is a malformed packet.php-src/ext/mysqlnd/mysqlnd_wireprotocol.c Line 2471 in b275e13
|
I think it can be done, but if We might try with libmysqlclient to see if we get the same result. (I haven't used libmysqlclient so it may take some time to verify.) |
Don't worry about libmysqliclient as we are no longer allowing it in mysqli. We can deviate from what that library does now. |
Thanks for your useful information! I'll try to see if I can fix this problem by modifying mysqlnd. On a side note, this document may be out of date. https://www.php.net/manual/en/mysqlinfo.library.choosing.php |
I think I got the solution. |
Changes to |
I have read the conversation, thank you for your time anyway. I appreciated that. |
Uh oh!
There was an error while loading. Please reload this page.
Description
$mysqli->ping()
should returnfalse
if the connection is broken but instead it produces the following error:Reproducing code: https://gist.github.com/TheNewHEROBRINEX/0a855115642216bc79203de5d6784c14
To simulate a broken connection you can restart the MySQL server.
PHP Version
PHP 8.2.8
Operating System
Ubuntu 23.04
The text was updated successfully, but these errors were encountered: