MySQL server has gone away - in exactly 60 seconds
The php option mysql.connect_timeout
is the reason for this. It's not only used for connect timeout, but as well as waiting for the first answer from the server. You can increase it like this:
ini_set('mysql.connect_timeout', 300);
ini_set('default_socket_timeout', 300);
MySQL error 2006: mysql server has gone away
It may be easier to check if the connection exists and re-establish it if needed.
See PHP:mysqli_ping for info on that.
mysqli_query(): MySQL server has gone away
To demonstrate my comments
It would be wise to use backticks around certain column names ( or all ) if they have special meaning within SQL - such as name
or time
$sql = $connection->prepare("INSERT INTO comments (`name`,`mail`,`homepage`,`comment`,`time`) VALUES (?,?,?,?,?)");
$sql->bind_Param('sssss',$name,$mail,$homepage,$comment,$time);
/* assign a variable to the `execute` method and test that var */
$result = $sql->execute();
if( $result ){
/* the statement is now finished with, close it */
$sql->close();
if(!addPics($connection, $image_content, $mime, $time)){
//other code
}
MySQL server has gone away, inconsistent error, caused by a single script
Looks like a timed-out or failed query. Please paste the sql query you are using. You can also try and see yourself where the query might cause this by pasting the query in your mysql IDE (Navicat is my favorite) and prepend it with 'explain extended' (no quotes). So your query would look like 'explain extended select ...(all 300 lines)'
Look for keys higher than 4, no primary keys and rows queried with really high numbers for starters.
Also, it looks like instead of a view you may want to consider creating a stored procedure in which you can select everything into a temporary table and then do the on-the-fly calculated value in the next query. Of course, you need to configure my.cnf to recognize temporary table so it can destroy it once the session is complete. Also, if you have any replication or cluster of servers, make sure to stop binlog before creating the temporary table and then start it once your queries are completed and your session is about to close.
If you like, please paste your my.cnf (mysql config file) to make sure your config is optimal for the large query.
Also, for trouble-shooting purposes, you may want to temporarily increase the max execution time in php.ini.
PDO: MySQL server has gone away
The B.5.2.9. MySQL server has gone away section of the MySQL manual has a list of possible causes for this error.
Maybe you are in one of those situations ? -- Especially considering you are running a long operation, the point about wait_timeout
might be interesting...
Executing mysqli_stmt- execute() causes MySQL server has gone away error
I think I now know what is causing the problem! I wish I'm right.
function getUsers() {
// here you are creating a Database instance,
// but you've left it in the air, because you just retrieved `query` from it.
$query = getConnection()->query('SELECT * FROM `users`');
// at this point, there are already NO Database instance,
// because you have no reference of it.
// thus what I've read about resources being garbage collected
// will now apply here.
$query->execute();
// this will fail, indeed, Mysql has gone away!
return $query->getRows();
}
You should, at least save the connection to another variable.
$conn = getConnection();
$query = $conn->query('SELECT * FROM `user`');
$query->execute();
return $query->getRows();
But as a proper solution you must keep a single connection alive through the whole script execution and use it for all queries.
Related Topics
How to Fix the Permission Error When I Call Session_Start()
PHP How to Round Down to Two Decimal Places
Byethost Server Passing HTML Values "Checking Your Browser" With Json String
PHP How to Start an External Program Running - Having Trouble With System and Exec
Assigning the Return Value of New by Reference Is Deprecated
Json_Decode Returns Json_Error_Syntax But Online Formatter Says the Json Is Ok
PHP - How to Merge Arrays Inside Array
Convert Var_Dump of Array Back to Array Variable
PHP Difference Between Array() and []
PHP X86 How to Get Filesize of ≫ 2 Gb File Without External Program
Match A^N B^N C^N (E.G. "Aaabbbccc") Using Regular Expressions (Pcre)
Symfony2 - Force File Download
Sort PHP Multidimensional Array by Sub-Value
How to Get Page Content Using Curl