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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T21:43:04+00:00 2026-06-04T21:43:04+00:00

I wonder if anyone has found any weird behaviours with apc_exists() , behaviour that

  • 0

I wonder if anyone has found any weird behaviours with apc_exists(), behaviour that causes the entire WAMP server to hang when using it together with apc_add() or apc_store()?
After a long session of “debugging” and minimizing the problem I ended up with the following code that causes my WAMP to crash.

As far as I can tell it requires 1 apc_exists() and 2 apc_add() accessing different keys. [thus it sounds like a deadlock-issue]
I run this script in chrome and then smashes F5-key until I get the rand-thingy to happen twice. At that time or the first time it usually hangs.

<?php
$result = "asdfioasdjfoasdjf";
if(apc_exists("asdf")) {
    echo("#1<br/>");
    apc_add("launcher", $result, 1);
} else {
    echo("#2<br/>");
    $result = "asdfasdfasdf";
    apc_add("launcher", $result, 10);
}
if(rand(0,100) < 4) {
    echo("#stored data!<br/>");
    apc_add("asdf", "2130130", 1);
}
?>

My system/setup:
Windows 7 64bit
WAMP 2.2d 32bit
PHP Version 5.3.10
apc version 3.1.9 | $Revision: 325040 $

Am I doing something wrong in the code? Is this related to windows / wamp or does it exist in other environments and php/apc-versions?
In the above case, if I replace apc_exists() with apc_fetch(), the system doesn’t crash, does anyone know why?

  • 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-06-04T21:43:06+00:00Added an answer on June 4, 2026 at 9:43 pm

    I believe I found the cause. It all comes down to this well put answer here on SO:

    First, it’s important to know that if one tries to store a key which already exists with a specific TTL, AND the ttl hasn’t passed yet, a new entry will be created; it doesn’t matter if the key is the same, internally there will be two entries of the same key.

    Second, APC can fail (miss). Even when there’s no apparent reason for it. Why? APC was apparently created favoring speed over consistency, meaning that when the APC driver is busy doing some cleanout, it will simply return NULL instead of waiting until it’s done, even though the data exists. The long version of this is here: http://phpadvent.org/2010/share-and-enjoy-by-gopal-vijayaraghavan

    So what’s going on in the specific case mentioned in the question? The time between each request is shorter than 1 second, the specified TTL of the keys, so duplicates can happen if you attempt to store the key here. “But, it’s using apc_add, shouldn’t that guarantee the key is stored only if it doesn’t already exist?” Apparently not 🙂 this is what causes the deadlock to be random: sometimes apc_add would work as you’d expect, some others it “misses”, that is, apc_add fails to understand there is another existing key even if it is there. This is probably not a problem if the TTL=0, because in such case the key is simply overwritten, but in the specific case of the question, it will store a duplicate as a result of erroneously failing to find the key AND the key having a TTL that hasn’t passed yet.

    Since now there are two entries with the same key internally, when apc_exists is used, it gets confused and hangs.

    Takeaways: don’t store flags on APC, and always have a fallback case prepared in case it “misses”. APC seems to work best when used only to store copies of stuff that exists elsewhere (ie a file or a database entry)

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

Sidebar

Related Questions

I wonder if anyone has found a way to send at mid rendering the
I wonder if anyone has any recommendations as to setup of emacs 23 on
I have a requirement I'm fairly stuck on and wonder if anyone has any
I wonder if anyone here has any experience with mercurial running on Ubuntu? I've
Xcode no longer supports ibplugins so I wonder if anyone has any experience using
Wonder if anyone has any thoughts on this, I'm putting a Wordpress theme toegther
I wonder if anyone has an idea how you have to transform an image
I wonder if anyone has faced the same problem. When we done some modification
I wonder if anyone can think of a good technique to enable any arbitrary
I wonder if anyone has used this lightbox plugin and encountered a bug on

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.