Solved

Error: "MySQL server has gone away"

Posted on 2010-11-14
7
516 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
  • 3
  • 3
7 Comments
 
LVL 77

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 77

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
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 
LVL 77

Accepted Solution

by:
arnold earned 500 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
This article discusses four methods for overlaying images in a container on a web page
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to count occurrences of each item in an array.

778 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