|   | php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login | 
| 
  [2010-08-07 13:32 UTC] paulgao at yeah dot net
 Description:
------------
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:
---------------
<?php
mysqli = new mysqli("localhost", "xxx", "xxx");
/* check connection */
if (mysqli_connect_errno()) {
    printf("Connect failed: %s\n", mysqli_connect_error());
    exit();
}
sleep(31);
/* check if server is alive */
if ($mysqli->ping()) {
    printf ("Our connection is ok!\n");
} else {
    printf ("Error: %s\n", $mysqli->error);
}
/* close connection */
$mysqli->close();
?>
Expected result:
----------------
Our connection is ok!
Actual result:
--------------
Error: MySQL server has gone away
Patcheslibrary (last revision 2018-04-15 10:54 UTC by jajularavindra at gmail dot com)Pull RequestsHistoryAllCommentsChangesGit/SVN commits             | |||||||||||||||||||||||||||||||||||||
|  Copyright © 2001-2025 The PHP Group All rights reserved. | Last updated: Fri Oct 31 19:00:02 2025 UTC | 
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: if (GET_CONNECTION_STATE(&conn->state) > CONN_ALLOCED) { DBG_INF("Connecting on a connected handle."); if (GET_CONNECTION_STATE(&conn->state) < CONN_QUIT_SENT) { MYSQLND_INC_CONN_STATISTIC(conn->stats, STAT_CLOSE_IMPLICIT); reconnect = TRUE; conn->m->send_close(conn); }