I'm a programmer specialising in performant and scalable systems using PHP and Ruby and cooking


Published:

PHP APC Potential Cache Slam Averted for Key

Whilst checking on some feedback from the great tool at New Relic I found that we were getting a number of errors:

"PHP APC Potential Cache Slam Averted for Key"

Now this sound ominous on it's own, however don't be alarmed it's a simple issue with APC setup.

One quick fix is to adjust your php config for apc by setting:

apc.slam_defense=0  
apc.write_lock=1  

This will prevent slam defence being activated but still prevent mutliple processes writing to the same cache key, which could be an issue with your running multiple PHP threads, in particular with PHP-FPM.

According to some this is a bug, listed here, and can be simply fixed by upgrading APC to version 3.19+ But what does it mean?

The slam defense setting tells PHP how to handle race conditions when multiple processes attempt to write the same file. This can be read directly as a percentage chance, so setting this to anything greater than 0 will mean an n% chance that the process will skip the operation.

Write lock is then required to prevent multiple processes writing to the same files thus preventing corrupted files and race conditions.