2006 MySQL server has gone away

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
User avatar
SmokyBarnable
Forum Contributor
Posts: 105
Joined: Wed Nov 01, 2006 5:44 pm

2006 MySQL server has gone away

Post by SmokyBarnable »

I have been getting the following mysql error in my oscommerce cart lately and it's causing many problems:

2006 MySQL server has gone away

this happens randomly and after much research I have come to the conlusion that my host server wait timeout setting was to blame and/or server load. Since I am unable to change this server setting I tried this solution:

Code: Select all

tep_db_close ();
tep_db_connect() or die('Unable to connect to database server!'); 
This seemed to help a bit but the problem still is occuring. The problem usually happens during checkout when it takes a few seconds to process payment via api and performing a database insert. I have tried optimising and repairing tables with no effect.

Can anyone offer any suggestions other then switching hosting companies? I was hoping there was something I could do with code to eliminate this issue.

Thanks.


It might have something to do with curl_exec.
User avatar
SmokyBarnable
Forum Contributor
Posts: 105
Joined: Wed Nov 01, 2006 5:44 pm

Re: 2006 MySQL server has gone away

Post by SmokyBarnable »

I noticed the api request to my merchant processor seems to happen in a curl_exec command. My theory is that this command takes time and the CURLOPT_TIMEOUT , which is set 180, overrides the mysql wait_timeout on my server. So when it finishes the curl command it expects the connection to the database to still be open. Does this logic make any sense?

I have tried this modification.

Code: Select all

       
tep_db_close (); 
$response = curl_exec($ch);
tep_db_connect() or die('Unable to connect to database server!');
The functions are in oscommerce and use mysql_close and mysql_connect.
Post Reply