Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6739357
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T11:28:41+00:00 2026-05-26T11:28:41+00:00

i use memecached on my website (php, mysql, apache, ubuntu..) it work very fast

  • 0

i use memecached on my website (php, mysql, apache, ubuntu..) it work very fast but on “peak hours” i get a lot of “could not connect” error message, sometime users need to refresh 5 time for see the content.

I have 24 gb ram on my server and “top” command give me this for the memcached process:

4135 nobody    20   0  161m  37m  836 S    7 (%CPU)  0.2 (%MEM)   0:07.06 memcached

I launch memcached server like this:

memcached -d -u nobody -m 8192 -p 12000 -c 11212

And this is my PHP function:

<?
function cache_sql($query,$update,$time=0)
{

    $m = new Memcache;
    $m->connect('localhost', 11211) or die ("Could not connect");

    $file = $m->get(md5($query));

    if($update == 1)
    {
        $results = mysql_query($query);
        while($data = mysql_fetch_array($results)){$records[] = $data;}

        if(!$file)
        {
            $m->set(md5($query), $records, NULL, $time);
        }
        else
        {
            $m->replace(md5($query), $records, NULL, $time);
        }
    }
    else
    {
        if(!$file)
        {
            $results = mysql_query($query);
            while($data = mysql_fetch_array($results)){$records[] = $data;}

            $m->set(md5($query), $records, NULL, $time);
            return $records;
        }
        else
        {
            return $file;
        }
    }

}
?>

I am doing it right?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T11:28:43+00:00Added an answer on May 26, 2026 at 11:28 am

    I think you accidentally flipped the -c and -p parameters when starting memcached:

    memcached -d -u nobody -m 8192 -p 11212 -c 12000
    
    • first, make sure you have the latest versions of the php pecl/memcache since there were a few bugs
    • Take a look at the logs, is there any error, or notice being reported on the connection failure?
    • take a look at /etc/memcached.conf; in particular MAXCONN – the number of connections
    • in a terminal use telnet 127.0.0.1 11211 and then type stats to see curr_connections and total_connections
    • currently you aren’t using persistent connections which would speed things up, though I’m not sure it would necessarily help connecting. To use persistent connections:

    replace

    $m->connect('localhost', 11211) or die ("Could not connect");
    

    with

    $m->addServer('localhost', 11211) or die ("Could not connect");
    
    • also, I should point out that if your query often has different variables in the where clause, this kind of caching would always fail. You might want to log when a cache miss occurs
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Assuming a MySQL datastore, when would you NOT want to use memcached in a
Is is always advantages to use memcache to improve performance of MySQL query ?
I use the memcache extension for python, and I have a very strange problem.
I am thinking of writing a PHP extension library that will use the memcached
Is it good idea to use Memcached for session storage with PHP? We will
I use MySQL for my primary database, where I keep the actual objects. When
My goal is to use Facebook Login on a website with as few api
We have a PHP website like reddit, users can vote for the stories. We
If you need caching in your website to make database use lower, do you
Our current project at work is a new MVC web site that will use

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.