Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Sporadic MySQL Database Connection Failure


InternetKev

Recommended Posts

Posted

Occasionally the following MySQL error is generated:

 

Warning: mysql_connect(): Can't connect to MySQL server on '***.***.***.***' (10060) in

D:\.......\includes\functions\database.php on line 20

Unable to connect to database server!

 

I also ran a Google search for: Warning site:************.com and found several Google results had the same error. Google captured the same MySQL error on multiple OSC pages within the site (index.php, product_info.php pages).

 

A couple more notes:

  • My hosting company hosts the web and MySQL server on separate machines
  • The PHP.ini timeout defines a long timeout
  • The hosting company has been alerted to the sporadic error, however they say the MySQL isn't the issue.

My questions are:

  • Is this an OSCommerce problem?
  • Has anyone else encountered this error, and if you have, what did you do to correct it?

Posted

since it's intemittent I doubt is a code bug. Is likely too many accesses to the dbase at a given time. Consider cacheing the sql queries but first check if that is the case I believe there are contributions that allow monitoring of the mysql access and your host may have some reports about this.

Posted

I am having the same issue.

Warning: mysql_connect() [function.mysql-connect]: Too many connections in

/home/PATH/PATH/includes/functions/database.php on line 19

Unable to connect to database server!

 

All the research I have done so far is telling me it is an issue with my host. Out of curiosity...could I do this to gracefully catch the error in the database.php file?

 

if (USE_PCONNECT == 'true') {

$$link = mysql_pconnect($server, $username, $password);

} else {

$$link = @mysql_connect($server, $username, $password) or die ("Could not connect to the database server at this time. Please try later.");

}

 

Or some simple message like that?

 

Any advice would be greatly appreciated.

Kind Regards,

Tom

Posted
Sounds like your host has limited the number of simultaneous connections to your database server. If you have persistent connections enabled try setting that to false, it may help some.

 

I appreciate the recommendation. I checked the config file and it is set to false. This is what my host suggested to me...let them move my database from a remote dbserver to my local webserver...the same one my site is hosted on. Does anyone have any opinions? Thank you very much for your suggestions / comments.

Tom

Posted

The hosting company says that the MySQL server is not overwhelmed, however they have been watching the logs for spikes. Nothing yet.

 

Caching queries sounds like a good idea, especially if the hosting company has occasional MySQL spikes. Is there a contribution that anyone prefers?

 

Thanks again :thumbsup:

Posted

Kevin,

this is NOT a solution, however, this is how I am monitoring this and maybe you would like to do the same?

I altered the database.php file to gracefully handle the error and so I can monitor missed connections by having an email sent to me if no connection is found. I have multiple oscommerce installs...so I tested it first on a beta site.

IF ANYONE SEES AN ISSUE WITH ME DOING THIS PLEASE LET ME KNOW. I am pretty green to php/mysql...and I'm sure someone will tell me about a log file or something<grin>.

 

if (USE_PCONNECT == 'true') {

$$link = mysql_pconnect($server, $username, $password);

} else {

$$link = @mysql_connect($server, $username, $password) or die('<img src="STORE LOGO"><br />We\'re sorrry, we encountered and error. This is just a minor error and your information has not been lost. Please try clicking <a href="HOME LINK">here</a> to return to our homepage. We apologize for the inconvenience. If you continue to have trouble please contact <a href="mailto:ADMINEMAIL?subject=DBCONNECTION">[email protected]</a>' . mail('MAILTO EMAIL, 'NO MYSQL CONNECTION', 'NO MYSQL CONNECTION', 'FROM: [email protected]'));

}

 

Tom

Posted

Tom,

 

I'm going to try this code today.

 

I am very interested to see how many failures/emails are actually occurring.

 

Thanks,

Kevin

Posted

Tom,

 

I installed your database.php code, modified for the specific site, and tested it by editing the configuration.php database settings with incorrect credentials.

 

The error message worked great, and the email was sent as expected. It is working perfectly!

 

Might be handy to turn your code into a OSC contribution.

 

:thumbsup:

 

Kev

Posted

Kev,

Glad I could help. I wasn't sure if there was a better way to go about this, but it works for me...and now you too <grin>. Fortunately I have not had any troubles with my live site since I added this code, but it is good to know that if / when it happens again I'll be notified. FYI...if you don't have a site monitor you could try SiteUpTime. They have a free monitor that pings your site at 30 minute intervals and emails you if it fails. Of course you can purchase monitors at 2 / 5 minute intervals too, but that depends on your application. Just thought I would mention that since we were on the site monitoring subject :thumbsup:

 

Tom

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...