HelpNearMe
asked on
Error: "MySQL server has gone away"
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
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
ASKER
Thanks arnold,
What is the test?
HNM
What is the test?
HNM
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
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
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
look @ http://dev.mysql.com/doc/refman/5.0/en/gone-away.html
Tryincreasing the "wait_timeout" variable
Tryincreasing the "wait_timeout" variable
ASKER
madunix: I can use google too.. .as I said in my question I don't have access to the server settings.
ASKER
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
I found a typo that caused it. I closed the connection then tried to select the DB. Seems to work fine now.
HNM
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.