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 3946140
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T01:05:53+00:00 2026-05-20T01:05:53+00:00

I’ve this code in php using memcache : <?php $memcache = new Memcache; $memcache->connect(‘localhost’,

  • 0

I’ve this code in php using memcache :

<?php

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

$version = $memcache->getVersion();
echo "Server's version: ".$version."<br/>\n";

$tmp_object = new stdClass;
$tmp_object->str_attr = 'test';
$tmp_object->int_attr = 123;

$memcache->set('key', $tmp_object, false, 1) or die ("Failed to save data at t\
he server");
echo "Store data in the cache (data will expire in 1 second)<br/>\n";
$i=0;
do{
  $get_result = $memcache->get('key');
  echo "Data from the cache:<br/>\n";
  var_dump($get_result);
  $i++;
}while($get_result);
echo $i;
var_dump($get_result);

the value of $i is different every time.. Sometimes it is 140, sometimes it is 900+, etc… Why does it change ?

edit –
btw, that is an example program for memcached from php website with minor alterations.

edit
I guess I wasn’t clear enough with question :
I meant to ask, why does the $memcache->get('key') execution takes more cpu times in some cases while it takes less cpu time in other cases.
=> more loops means $memcache->get('key') happened to take less time, less loops means it took more cpu time.
Keep in mind that cache is set to expire within 1 second and do - while executes until it expires.

  • 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-20T01:05:54+00:00Added an answer on May 20, 2026 at 1:05 am

    Your loop keeps running and is reading the same key over and over again, until it is removed from memcache.

    The expire time for that key is set to 1 second, so the number of times the loop runs is the number of times the value can be read in 1 second. The expire time is just an indication. It doen’t necessarily have to be 1 second exact to the millisecond. And the speed of your script can depend on various other conditions as well, so this counter isn’t very reliable.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

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.