1

I have a website that has been working very well during last 2 years, but now the website has more visitors and more content. I'm using wordpress and due to that content and visitors, I'm, getting several connections to the database in ONE specific moment. How to solve this?

The account at bluehost was suspended because I have 97 connections to the MySQL database due to this website.

A possible solution to this problem may be:

A MESSAGE FOR THE VISITOR SAYING: The website isn't available in this moment.

How do I know when the maximum number of connections are exceeded?

Mike Purcell
  • 19,847
  • 10
  • 52
  • 89
user975718
  • 91
  • 4
  • 8
  • 2
    Take care with the word instance in this context, an instance refers to a mysql server, I think you mean 97 connections? – Mike Purcell Feb 11 '12 at 21:47

3 Answers3

2

There are a couple of options here:

  1. You can implement a caching layer via seanbreeden's suggestion, I am sure there are many available. Chances are many of your blog pages are static, so a cache plugin that caches the entire page will definitely help. Take a look at varnish.

  2. If caching still doesn't help, you may want to consider moving your application to a host who is more forgiving with regards to the total number of connections at any given time, perhaps even virtual private server, which are pretty cheap, check out Linode.com

  3. You could implement a database singleton which will help recycle database connections, this solution is a little more involved but will also help reduce the number of connections made.

-- Edit --

Looks like you can get current 'active' connections issuing a query like this:

mysql> SHOW GLOBAL STATUS LIKE 'Threads_connected';
+-------------------+-------+
| Variable_name     | Value |
+-------------------+-------+
| Threads_connected | 1     |
+-------------------+-------+
1 row in set (0.00 sec)    

I can't remember the exact code, but we implemented a 'retry' mechanism when a PDOException was raised and the code matched 'too many connections', we would sleep the query then retry $x amount of times.

Community
  • 1
  • 1
Mike Purcell
  • 19,847
  • 10
  • 52
  • 89
1

Find a caching plug-in for Wordpress and install it. Caching will lower the load on the database.

seanbreeden
  • 6,104
  • 5
  • 36
  • 45
1

There is a simple solution to this called caching.

You can install a cacheing plugin on your wordpress installation which will reduce the number of database connections needed.

For a list and comparison of cache plugins for wordpress, see this link: List of cache plugins

Relequestual
  • 11,631
  • 6
  • 47
  • 83