title: Memcached "Could not connect" error on peak hours
body: <p>i use <strong>memecached</strong> on my website (php, mysql, apache, ubuntu..) it work very fast but on "peak hours" i get a lot of "<strong>could not connect</strong>" error message, sometime users need to refresh 5 time for see the content. </p>
  
  <p>I have 24 gb ram on my server and "top" command give me this for the memcached process:</p>
  
  <pre>
  4135 nobody    20   0  161m  37m  836 S    7 (%CPU)  0.2 (%MEM)   0:07.06 memcached
  </pre>
  
  <p>I launch memcached server like this:</p>
  
  <pre><code>memcached -d -u nobody -m 8192 -p 12000 -c 11212
  </code></pre>
  
  <p>And this is my PHP function:</p>
  
  <pre><code>&lt;?
  function cache_sql($query,$update,$time=0)
  {
  
      $m = new Memcache;
      $m-&gt;connect('localhost', 11211) or die ("Could not connect");
  
      $file = $m-&gt;get(md5($query));
  
      if($update == 1)
      {
          $results = mysql_query($query);
          while($data = mysql_fetch_array($results)){$records[] = $data;}
  
          if(!$file)
          {
              $m-&gt;set(md5($query), $records, NULL, $time);
          }
          else
          {
              $m-&gt;replace(md5($query), $records, NULL, $time);
          }
      }
      else
      {
          if(!$file)
          {
              $results = mysql_query($query);
              while($data = mysql_fetch_array($results)){$records[] = $data;}
  
              $m-&gt;set(md5($query), $records, NULL, $time);
              return $records;
          }
          else
          {
              return $file;
          }
      }
  
  }
  ?&gt;
  </code></pre>
  
  <p>I am doing it right?</p>