---
title: Dealing with MySQL Too Many Connections error
description: One side effect of Doorbell's growth and popularity was a new error – Too Many Connections. Here is a quick overview of the cause and a solution.
image: https://blog.thoughtlabs.com/hubfs/Imported_Blog_Media/php.png
---

<https://www.thoughtlabs.com/>

- [About Us](https://www.thoughtlabs.com/about.html)
- [Our Services](https://www.thoughtlabs.com/services.html)
- [Our Clients](https://www.thoughtlabs.com/clients.html)
- [Our Blog](https://blog.thoughtlabs.com/blog/)
- [Our Book](https://www.thoughtlabs.com/book.html)
- [Free Resources](https://www.thoughtlabs.com/free-resources.html)
- [Speaking](https://www.thoughtlabs.com/speaking.html)
- [Contact Us](https://www.thoughtlabs.com/contact.html)

<https://twitter.com/thoughtlabs> <https://www.facebook.com/thoughtlabs>

![](https://blog.thoughtlabs.com/hubfs/Imported_Blog_Media/php.png)

# Dealing with MySQL Too Many Connections error

![John Maver](https://blog.thoughtlabs.com/hs-fs/hubfs/author-john-maver.png?width=50&height=50&name=author-john-maver.png)

Written by [John Maver](https://blog.thoughtlabs.com/blog/author/john-maver)

on Feb 17, 2008

![php](https://blog.thoughtlabs.com/hs-fs/hubfs/Imported_Blog_Media/php.png?width=350&name=php.png)

[Doorbell](http://apps.bebo.com/doorbellbe) on Bebo is growing steadily, despite some randomness in the Bebo platform uptime. One side effect of its popularity was a new error – Too Many Connections. Here is a quick overview of the cause and a solution.

Too Many Connections can be caused by either a lot of simultaneous connections or by old connections not being released soon enough. There are some simple changes you can make to your PHP code and your MySQL settings to prevent both.

There are two built in ways to connect to MySQL from PHP – permanent or interactive. You get a permanent connection using *mysql\_pconnect()*. This creates a permanent connection to the database (permanent is defined as 8 hours by the MySQL *wait\_timeout* system variable). It will only create a new connection if it cannot find an existing permanent connection to reuse. You need to be careful with *mysql\_pconnect()* to make sure that you don’t run out of connections, since these stay open so long and you cannot close them with *mysql\_close()*.

The other way is to use *mysql\_connect()*. This creates a new temporary connection, if the *new\_link* parameter is set to true, or reuses an existing one if it is not. This can be better than *mysql\_pconnect()* because these connections can be short lived, and can be closed when needed with *mysql\_close()*. An important parameter is the CLIENT\_INTERACTIVE flag. If this is passed, it will use the MySQL *interactive\_timeout* value instead of *wait\_timeout*. Since *wait\_timeout* defaults to 8 hours, this seems like a great idea. However, surprisingly, *interactive\_timeout* **also defaults to 8 hours**. You should change this value to something smaller that fits your system.

Using *mysql\_connect()* with *new\_link* set to false, passing the CLIENT\_INTERACTIVE flag, and adjusting *interactive\_timeout* will help stop problems with old connections jamming up the works.

To deal with many simultaneous connections, adjust the MySQL *max\_connections* variable. By default, it is set to 100. Increase this value to something that will support what you feel is realistic for your system.

A final thing to do after updating your code and MySQL is to flush the bad connections database with “*myqladmin flush-hosts*”. This will allow your web server to connect back to MySQL after all those Too Many Connection errors.

 Topics: [Programming](https://blog.thoughtlabs.com/blog/tag/programming)

**About the author:**

![John Maver](https://blog.thoughtlabs.com/hubfs/author-john-maver.png)

#### [John Maver](https://blog.thoughtlabs.com/blog/author/john-maver)

John Maver is a champion for building customer-centric social communities, with a focus on nurturing strong brand advocates. His creative campaigns are developed around meaningful interactions and making brands come alive. John loves mobile technology and is always exploring the latest apps and APIs that help people connect.

Find me on: <https://facebook.com/jmaver> <https://linkedin.com/in/jmaver> <https://twitter.com/jmaver>

 Copyright © 2026 Thought Labs, LLC. All rights reserved. Website Design & Development by [Metropolis](https://www.metropoliscreative.com)  |  [privacy policy](https://www.thoughtlabs.com/privacy.html)  |  [cookie policy](https://www.thoughtlabs.com/cookie-policy.html)  | 

cookie settings

```json
{
  "@context" : "https://schema.org",
  "@type" : "BlogPosting",
  "author" : {
    "@type" : "Person",
    "name" : "John Maver",
    "url" : "https://blog.thoughtlabs.com/blog/author/john-maver"
  },
  "dateModified" : "2024-03-20T18:52:33.029Z",
  "datePublished" : "2008-02-17T05:00:00.000Z",
  "headline" : "Dealing with MySQL Too Many Connections error",
  "image" : [ "https://blog.thoughtlabs.com/hubfs/Imported_Blog_Media/php.png" ],
  "mainEntityOfPage" : {
    "@id" : "https://blog.thoughtlabs.com/blog/dealing-with-mysql-too-many-connections-error",
    "@type" : "WebPage"
  },
  "publisher" : {
    "@type" : "Organization",
    "logo" : {
      "@type" : "ImageObject",
      "url" : "https://blog.thoughtlabs.com/hubfs/Email/TL%20Logo%20Wide.png"
    }
  }
}
```