20

The documentation on php.net is very spotty about causes of failure for APC writes. What kind of scenarios would cause a call to apc_store() to fail?

There's plenty of disk space available, and the failures are spotty. Sometimes the store operation will succeed and sometimes it'll fail.

jodonnell
  • 49,859
  • 10
  • 62
  • 67

9 Answers9

55

For php cli it needs to be enabled with another option: apc.enable_cli=On

In my situation it was working when running from a webbrowser, but not when executing the same stuff with php cli.

Kees van Dieren
  • 1,232
  • 11
  • 15
10

I had exactly the same situation.

I migrated my code from using Cron Jobs, to using Gearman Workers, which were managed through supervisord.

Everything Broke. I couldn't ever get caches to work through APC, and had to revert back to using filebase caching.

Eventually I figured out that when I was using cron jobs, I would load each page via wget, rather than command line. This difference, meant that supervisord, which would load my PHP scripts via command line, wouldn't work, because by default APC will not work through command line.

The fix....

apc.enable_cli=On

Layke
  • 51,422
  • 11
  • 85
  • 111
6

out of memory (allocated memory for apc, that is)

Nir Levy
  • 4,613
  • 2
  • 34
  • 47
4

this asinine (and closed, for some reason) bug was my problem:

http://pecl.php.net/bugs/bug.php?id=16814

has to roll back to apc version 3.1.2 to get apc to work. no fiddling with apc settings in php.ini helped (i'm on mac os 10.5, using apache 2, php 5.3).

for me, this test script showed 3 "trues" for 3.1.2 and true/false/true for 3.1.3p1

var_dump( apc_store('test', 'one') ); var_dump( apc_store('test', 'two') ); var_dump( apc_store('diff', 'thr') );

Paul
  • 739
  • 5
  • 11
2

http://php.net/manual/en/apc.configuration.php

the apc.ttl and apc.user_ttl settings on php.ini:

Leaving this at zero means that APC's cache could potentially fill up with stale entries while newer entries won't be cached.

byterussian
  • 3,539
  • 6
  • 28
  • 36
1

Out of disk space or permission denied to the storage directory?

Greg
  • 316,276
  • 54
  • 369
  • 333
1

In addition to what Greg said, I'd add that a configuration error could cause this.

Tom
  • 776
  • 1
  • 5
  • 12
1

There's a bug in the version installed with ubuntu 10.04 and debian stable. If you replace the package with this version: http://packages.debian.org/sid/php-apc (3.1.7) it works as it should.

jw01
  • 51
  • 1
  • 4
0

apc_store will fail if that specific key already exists and you are trying to write again to it before the TTL expires. Therefore you can pretty much ignore the return false because it really did fail but the cache is still there. If you want to get around this, start using apc_add instead. http://php.net/manual/en/function.apc-add.php

ty91011
  • 86
  • 3
  • 4
    Thats wrong: `apc_store()` overwrites existing keys without failing (--> it returns `true`). `apc_add()` is the one, that _really_ fails on duplicate keys (as the name suggests) – KingCrunch Jan 09 '13 at 22:38