Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PHP

websocket 2006 MySQL server has gone away

Opened connection from mysql client to the database is not intended to be open for several hours. 
After some time the client disconnects.
Technically, when making a WebSocket request, we can do mysqli::ping - ping the connection to the server or try to reconnect if the connection is lost.

$mysqli = new mysqli("localhost", "my_user", "my_password", "world");

/* check connection */
if ($mysqli->connect_errno) {
    printf("Connect failed: %s
", $mysqli->connect_error);
    exit();
}

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

/* close connection */
$mysqli->close();
Source by www.php.net #
 
PREVIOUS NEXT
Tagged: #websocket #MySQL #server
ADD COMMENT
Topic
Name
3+6 =