2

I have a CS-CART ecommerce set up on a shared server. Lately it had some problems and I'm getting mysql errors, like these ones:

PHP Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in /home/mp/public_html/core/db/mysql.php on line 53
PHP Warning: mysql_errno(): supplied argument is not a valid MySQL-Link resource in /home/mp/public_html/core/db/mysql.php on line 57
PHP Warning: mysql_errno(): supplied argument is not a valid MySQL-Link resource in /home/mp/public_html/core/db/mysql.php on line 57
PHP Warning: mysql_error(): supplied argument is not a valid MySQL-Link resource in /home/mp/public_html/core/db/mysql.php on line 64
PHP Warning: mysql_errno(): supplied argument is not a valid MySQL-Link resource in /home/mp/public_html/core/db/mysql.php on line 127

The weird thing is that I randomly receive the error, on random pages. It's not something that appears on a certain page or after doing a certain thing.

To make things more complicated, this only happens sometimes. Is there any chance that this could be caused by the server/mysql process?

For example, the website loads excellent now, all features work flawlessly - I tested most of the features, pages, and I did not receive the errors. A few hours ago everything loaded slow and some of the pages returned the errors above.

Any input will be appreciated. Thank you.

ChrisNN
  • 35
  • 3

1 Answers1

2

Errors like this can happen if the MySQL server isn't reachable and PHP error handling is not implemented to anticipate this. mysql_connect() returns as MySQL resource pointer to the database server, but only if the connection actually works. If not, the resource pointer is empty and functions further down the line start to complain, which is what you're seeing there. If this happens only intermittently, this is a typical sign of MySQL server overload.

If you're on a shared hosting server, chances are that another tenant is sometimes exhausting all the resources, so there is little you can do. But there may be a couple of things you can do to trace the problem further. If your phpMyAdmin interface allows you access to the Status tab, you can use it to gain some insight into the MySQL server's status.

For example, look at the number of queries it performs, and the number of simultaneous connections it allows. Sometimes, connections are denied because the max connection number is exhausted (some hosting environments allow you to change this). The server also keeps track of the failure statistics, it might give you some clues as to what's going on.

However, if you have no access to those statistics, or can't change any settings on the server and you are sufficiently sure that your app isn't causing the traffic overload, you should probably open a support ticket with your hosting provider.

Udo
  • 1,784
  • 11
  • 9
  • I think this could be the reason. The errors are too random to be from something else. Could it be a bad SQL query that hangs the mysql process? For example, once the query is ran, the mysql process is overloaded and all other queries will run slow and even return errors. Does the mysql process have a timeout or something similar? – ChrisNN Dec 07 '11 at 13:08
  • Yes, it could absolutely be a slow query. The Status page also shows you slow-running queries and how often they happen. While most PHP environments have a per-request timeout (usually between 30 and 60 seconds), MySQL queries do not. So it is absolutely possible to have zombie queries around even though the process that called them originally is long dead. Again, on a shared hosting environment it is absolutely possible you're suffering for someone else's sins here. – Udo Dec 07 '11 at 13:22
  • Someone else also mentioned that this - http://dev.mysql.com/doc/refman/5.0/en/gone-away.html - could be the problem. What do you think? – ChrisNN Dec 07 '11 at 14:59
  • I don't know CS-CART (or the bugs it might have), but under normal circumstances that shouldn't happen. You could try to test for this by logging every mysql_connect() call and see if the connection goes away while the request is being executed. It might also be worthwhile to look whether this always happens on the same page or while doing the same operation. Logging things like this will most likely involve you going into the source file, placing logging calls there. – Udo Dec 07 '11 at 16:03
  • You could also test your app and server by calling Apache Bench on it. This hammers the app with thousands of requests. If you see the error appearing during that time, you have a problem on your end. – Udo Dec 07 '11 at 16:04
  • I will try. The latest status that I received from the hosting company is that I have a few mysql connections in 'sleep' status. Probably, when the number of 'sleep' connections grows it causes all the problems. – ChrisNN Dec 08 '11 at 14:17