Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Error: "MySQL server has gone away"

Posted on 2010-11-14
7
Medium Priority
?
529 Views
Last Modified: 2012-05-10
Hi Experts,

I have written a bit of PHP script to query a DB and loop through 1200+ rows and build a couple multidimensional arrays.  The trouble is that the queries & loops etc take so long that it appears the server connection closes.

When I lower the loop count limit to 3 or for instead of 1200 I don't get any errors and everything is great.  So it seems to be related to the time it takes to complete the script.

It's a godaddy MySQL server so I doubt that I have control over reconnect & timeout parameters.  Is there anything in the script I can do to hold the connection open or should I open and close the connection with every loop iteration?

I am getting this error later in the script when I try an insert after the big time consuming loop: MySQL server has gone away.
.

Thanks,

HNM
0
Comment
Question by:HelpNearMe
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
7 Comments
 
LVL 80

Expert Comment

by:arnold
ID: 34131920
The error means that the connection you had defined/opened is no longer valid.  There is a test to make sure the connection is till present before even trying to pass a transaction.

The other option which is not available to you is to increase the idle connection timeout.  Or during the loop you check/send a noop through the connection.
0
 

Author Comment

by:HelpNearMe
ID: 34132054
Thanks arnold,

What is the test?

HNM
0
 
LVL 80

Expert Comment

by:arnold
ID: 34132146
http://www.wallpaperama.com/forums/simple-php-mysql-connection-test-script-example-t5702.html


Another approach is to generate the request, close the connection if it is not needed and then reconnect when you need to interact with the database.
http://php.net/manual/en/function.mysql-ping.php
0
Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

 
LVL 80

Accepted Solution

by:
arnold earned 2000 total points
ID: 34132198
you would have
$mysql_connection_reference=mysql_connect();

you would then run mysql_ping($mysql_connection_reference); which will either return true that the connection is present or will reestablish the connection.
0
 
LVL 25

Expert Comment

by:madunix
ID: 34132729
look @ http://dev.mysql.com/doc/refman/5.0/en/gone-away.html 
Tryincreasing the "wait_timeout"  variable
0
 

Author Comment

by:HelpNearMe
ID: 34132855
madunix:  I can use google too.. .as I said in my question I don't have access to the server settings.
0
 

Author Closing Comment

by:HelpNearMe
ID: 34132936
Thanks arnold,

I found a typo that caused it.  I closed the connection then tried to select the DB.  Seems to work fine now.  

HNM
0

Featured Post

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses how to implement server side field validation and display customized error messages to the client.
In this blog, we’ll look at how improvements to Percona XtraDB Cluster improved IST performance.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

609 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question