Solved

Error: "MySQL server has gone away"

Posted on 2010-11-14
7
514 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
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.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
join tables 4 50
Form Processing in PHP 11 29
Session timeout 5 13
PHP get array item with custom id 4 18
Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
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.
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…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

943 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

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now