While installing PHP APC, I received two unexpected questions. I had previously installed APC at a test environment and did not receive these questions.

The questions are:

  • Enable per request file info about files used from the APC cache
  • Enable spin locks (EXPERIMENTAL)

Here are the initial few lines of installation:

# pear install pecl/apc
WARNING: channel "pecl.php.net" has updated its protocols, use "channel-update pecl.php.net" to update
downloading APC-3.1.6.tgz ...
Starting to download APC-3.1.6.tgz (148,835 bytes)
..........................done: 148,835 bytes
49 source files, building
running: phpize
Configuring for:
PHP Api Version:         20041225
Zend Module Api No:      20060613
Zend Extension Api No:   220060519
 1. Enable per request file info about files used from the APC cache : no

1-1, 'all', 'abort', or Enter to continue: 
 1. Enable spin locks (EXPERIMENTAL) : no

1-1, 'all', 'abort', or Enter to continue: 
building in /var/tmp/pear-build-root/APC-3.1.6
running: /var/tmp/APC/configure --enable-apc-filehits=no --enable-apc-spinlocks=no

Does anyone know what these questions do? What would the proper answers be?

  • I can help a (very little) bit: they correspond to --enable-apc-filehits and --enable-apc-spinlocks, but I don't know offhand exactly what each of those does.
    – BMDan
    Dec 28 '10 at 21:23

The short answer is options can generally be left at the defaults, which you can take to be the "proper" answers.

The first option (--enable-apc-filehits) enables gathering information for the "filehits" option of apc_cache_info. Basically, you can use it to figure out which files are pulled from the cache for each request if you're debugging cache-related problems. From the apc_cache_info documentation:

If cache_type is "filehits", information about which files have been served from the bytecode cache for the current request will be returned. This feature must be enabled at compile time using --enable-filehits.

When it comes to the second option (--enable-apc-spinlocks), spinlocks are a processor-cycle inefficient way of ensuring only one process accesses a resource at any given time. APC uses locks when dealing with shared memory. APC places the cache in shared memory so that all the PHP processes can, well, share the cache, and locks ensure that the processes don't trip over each other while doing it.

As of APC 3.1.9, the PECL installer ask about enabling three additional options: memory protection, pthread read/write locks and pthread mutexes, which correspond to --enable-apc-memprotect, --enable-apc-pthreadrwlocks and --enable-apc-pthreadmutex. The first two are labeled experimental and disabled by default; the latter is enabled.

Memory protection treats some areas of shared memory as read-only in certain circumstances.

Pthread read/write locks and mutexes are alternate locking mechanisms. The locking mechanisms that APC can currently use are:

  1. file locking (fcntl)
  2. semaphores
  3. pthread locks
  4. pthread mutexes
  5. Slim reader/writer locks (Windows only)
  6. spinlocks

Stick to the default locking mechanism unless APC won't compile. Brian Shire at Facebook tested locking mechanism performance and presented the results back in 2007; you can use his results to guide you when trying locking mechanisms when the defaults fail.


Instead of using AB for benchmarks, you should use siege wich is more accurate.


are you sure apc is enabled?

php -i | grep apc 

Just because it is installed does not mean it is loaded in php

  • Yes apc was installed. I'll edit the question now and remove my remarks about the speed comparison, it is not extremely relevant to the main question.
    – Haluk
    Aug 26 '11 at 19:24
  • installed yes.. running though? php -i spits out a phpinfo to console
    – Mike
    Aug 26 '11 at 21:37
  • Hi Mike, yes it is definitely running. We've been using its variable cache since the installation. Regardless, the question was not intended to be about if apc is running or not. I've cleared the question's irrelevant parts.
    – Haluk
    Aug 26 '11 at 22:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.