|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #52561 function mysqli_ping no attempted reconnection!
Submitted: 2010-08-07 13:32 UTC Modified: 2014-10-16 16:39 UTC
Avg. Score:4.0 ± 1.2
Reproduced:22 of 24 (91.7%)
Same Version:6 (27.3%)
Same OS:8 (36.4%)
From: paulgao at yeah dot net Assigned: mysql (profile)
Status: Wont fix Package: MySQL related
PHP Version: 5.3.3 OS: irrelevant
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Bug Type:
From: paulgao at yeah dot net
New email:
PHP Version: OS:


 [2010-08-07 13:32 UTC] paulgao at yeah dot net
I use mysqli_ping reconnection database when php script long time run.
when my use mysqlnd module, mysqli_ping() is run fail, errormsg is "MySQL server has gone away".

mysqli.reconnect setting is ON. 
mysql server timeout is 30s.

Test script:
mysqli = new mysqli("localhost", "xxx", "xxx");

/* check connection */
if (mysqli_connect_errno()) {
    printf("Connect failed: %s\n", mysqli_connect_error());
/* check if server is alive */
if ($mysqli->ping()) {
    printf ("Our connection is ok!\n");
} else {
    printf ("Error: %s\n", $mysqli->error);

/* close connection */

Expected result:
Our connection is ok!

Actual result:
Error: MySQL server has gone away


library (last revision 2018-04-15 10:54 UTC by jajularavindra at gmail dot com)

Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2010-08-07 13:41 UTC] paulgao at yeah dot net
and mysql server version 5.1.49.
 [2010-08-07 13:53 UTC]
-Status: Open +Status: Assigned -Assigned To: +Assigned To: mysql
 [2010-08-14 18:41 UTC]
Does this happen with libmysql aswell?
 [2010-08-14 19:28 UTC] paulgao at yeah dot net
when i use libmysql, sleep 31s+, mysqli_ping() is work, it can reconnection.
 [2010-08-18 12:23 UTC]
-Status: Assigned +Status: Wont fix
 [2010-08-18 12:23 UTC]
You are using mysqlnd and it doesn't reconnect. It has no such capability by design. reconnect is off by default since ages and is considered dangerous. Thus, reconnect wasn't implemented in mysqlnd. Ergo, mysqli.reconnect has no meaning.
You can either stay with libmysql, which however is not recommended in the long run. Or change your code so you reconnect explicitly.
 [2014-09-26 23:40 UTC] jay at grooveshark dot com
This caused problems for us trying to upgrade. Why is ping/reconnect considered dangerous? It has been working fine for us problem free for years.
 [2014-10-16 16:39 UTC]
It is not implemented because reconnect creates a new connection which has new state and the state of the old connection is gone - session variables, transaction. In this context automatic reconnect is considered dangerous and is disabled since years in libmysql. mysqlnd doesn't provide this for the very same reason.
 [2017-03-07 17:59 UTC] claudio dot galdiolo at gmail dot com
Hi, the documentation of this function is not clear, I read these 3 statements:

Checks whether the connection to the server is working. If it has gone down and global option mysqli.reconnect is enabled, an automatic reconnection is attempted.

Note: The php.ini setting mysqli.reconnect is ignored by the mysqlnd driver, so automatic reconnection is never attempted.

This function can be used by clients that remain idle for a long while, to check whether the server has closed the connection and reconnect if necessary.

Statement #1 says that "an automatic reconnection is attempted".
Followed by statement #2 saying "automatic reconnection is never attempted".
Followed by statement #3 saying "reconnect if necessary".
 [2018-11-27 09:22 UTC] qianqian dot bu at microsoft dot com
May I ask if reconnection is not supported, what is the usage of the reconnect flag in MYSQLND_METHOD(mysqlnd_conn_data, connect)?  May I ask a help that could you give me a use case for understanding?

The code piece is something like below:
		DBG_INF("Connecting on a connected handle.");

		if (GET_CONNECTION_STATE(&conn->state) < CONN_QUIT_SENT) {
			reconnect = TRUE;
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 12 14:01:34 2024 UTC