I often got error message, and the Connection timed out duration is from minutes to hours.
mysqli::query(): MySQL server has gone away
mysqli::mysqli(): (HY000/2002): Connection timed out
I try to do same settings from similar questions in stackoverflow and MySQL Manual
But mysql.connect_timeout
and default_socket_timeout
are not available settings in phprc on my host(DreamHost)
SET GLOBAL statements
in PhpMyAdmin is also not allowed, so I cannot set max_allowed_packet
on my host(DreamHost)
I already set in phprc
memory_limit = 128M //The max available value on my host(DreamHost)
I also put these codes in the beginning of .php file(I think this is in vain because they are not available settings in phprc)
ini_set('mysql.connect_timeout', 18000);
ini_set('default_socket_timeout', 18000);
//18000 a little bit crazy I know
Are there anything I can try to avoid
Connection timed out
andMySQL server has gone away
? In PHP way?
How about add this in my .php file? Whenever Connection timed out
happened then kill php
<?php
if(preg_match("/Connection timed out/", mysqli_connect_error()) ){
exec ( "killall -9 php55.cgi" );
//This won't work, when My php exec kill command, I get "`500 Internal Server Error`" from browser
}
?>
I guess sometimes table marked as crashed and should be repaired
is due to Connection timed out
? Because in PhpMyAdmin table status always OK.