Solved

Error: "MySQL server has gone away"

Posted on 2010-11-14
7
518 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 78

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 78

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
Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

 
LVL 78

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

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…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
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 …

726 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