0

First of all, I already went through some related posts, but without luck.

I followed the solution provided in MySQL server has gone away - in exactly 60 seconds setting this values at the very beginning:

ini_set('mysql.connect_timeout', 300);
ini_set('default_socket_timeout', 300);

but it seems that the error persist.

The error occurs just before perform a query: the database class used for handling the mysql operations, perform a ping (mysqli_ping) in order to refresh the connection (guess that's the meaning of using mysql ping) but in certain point, ~60 it throws this warning:

Warning: mysqli_ping(): MySQL server has gone away in...

Is there something I missing?

UPDATED I figured out where exactly the issue is.

I will explain further my workflow. I establish two different DB connections, the first one I do is just for retrieve data, and the second one, is used to insert all data obtained (row by row). Due to the second connection is the one that is performing operations, I thought that that's the one producing the server's gone away, but it turns out that the error is raise by the idle connection (the first one).

The workaround I made is to close the connection (the first one due to it will be no longer used) just after the data was queried.

The second connection has enough time to not reach a timeout.

The first connection is to a remote database and the second one is made to my local server, so I have completely control over the second one.

The weird thing with the connection I do to the remote MySQL server is that, when I connect from my PHP script, after the 60 seconds or so, it reaches the timeout, but if I connect it from the console, the connection is not timing out. Do you know how can I managed to not get that timeout (server has gone away)? As I said above, I already have a workaround to this, but I'd like to know why from PHP is timing out after ~60 seconds whereas from the console I can stay connected per hours.

Community
  • 1
  • 1

1 Answers1

3

Those configs that you're setting change the client connection, this problem is related to the server: it's the server that is closing the connection. To change this configuration you must change the value of wait_timeout on the my.cnf

Sources: http://dev.mysql.com/doc/refman/5.7/en/gone-away.html http://dev.mysql.com/doc/refman/5.7/en/server-system-variables.html#sysvar_wait_timeout

Just one more thing: change this may be not the best thing that you can do. Try to improve you query first.

Diego Oliveira
  • 432
  • 1
  • 4
  • 8