I want to use APC in a shared environment, but the main problem is of course, opcode sharing.

To overcome this, I've thought about using different apc.mmap_file_mask for each user (they're chrooted through php-fpm), so the "file" created by APC would not be shared, but would be personal to the user.

Of course, I've noticed I'm wrong for serveral reasons... and the biggest one is about "What does really do apc.mmap_file_mask?": I've thought it was like a pointer to the memory region used by APC, but i'm not that sure about it.
And, of course, there is no file in the path I've used (/tmp/apc.XXXXXX): no file on the machine's /tmp, and no file in the chrooted environment's (/home/vhosts/0001/tmp).
So, what does really do apc.mmap_file_mask?

My actual configuration is:

apc.mmap_file_mask = /tmp/apc.XXXXXX
apc.num_files_hint = 2048
apc.max_file_size = 10M
apc.ttl = 7200

I've already checked what happens with phpinfo(), and it doesn't translate the value: it still gives me /tmp/apc.XXXXXX (but apc.php says the cache was hit and I have better timing values... thus it is working).

2 Answers 2


Have you tried APC.php on the active web server? if you are using SHM and not MMAP that could explain this. The filemask simply allows it to save the ap file with random digits as per your specification to a particular location. You can even send it to /dev/zero as per a blog post here http://www.nigeldunn.com/2011/05/02/unable-to-allocate-memory-pool/

Here is explanation of various memory/file locations https://stackoverflow.com/questions/904581/shmem-vs-tmpfs-vs-mmap

I am not entirely certain of my answer but it is plausible that you are using SHM and hence the parameter for mmap mask may not apply.

try this as well after laoding your APC.php

ls /dev/shm
  • There is no file created in /dev/shm, and no files are present in /tmp like it should be according to my configuration. So, the problem remains... but the link you provided (at nigeldunn.com) looks to be really interesting since my configuration seems to be screwed up as well (apc.php says "100% fragmentation"), so I'm gonna fix it with his advices (so, thanks about it! :) ). I'll try some experimentations about mmapping files, and let you know what happens! :P Jul 4, 2012 at 3:49
  • 1
    Okay, after having tested it for a while I can say: nothing happens. No files are created anywhere, and everything seems to be allocated just into the ram. Mar 26, 2013 at 15:20

In case it's useful to anyone, the files get deleted almost immediately which is why you can't see them via ls (unless you happen to run ls just at the right second). If you'd like to see files being created and deleted by APC in the directory specified by apc.mmap_file_mask, you can use inotify-tools to monitor filesystem activity in that directory.

Just install it and change to the apc.mmap_file_mask directory and run the following command. If other processes use that directory for other things (such as in the case of /tmp), you can pipe the output to grep and look for part of the filename that matches your mmap_file_mask setting such as 'apc.'

/usr/bin/inotifywait -mr -e attrib,create,delete,modify,move --format '|%w/%f| %e %T' --timefmt '%Y-%m-%d-%H-%M-%S' .

#example output:

Setting up watches.  Beware: since -r was given, this may take a while!
Watches established.
|.//apc.wi3mjq| CREATE 2014-07-09-20-59-01
|.//apc.wi3mjq| MODIFY 2014-07-09-20-59-01
|.//apc.wi3mjq| DELETE 2014-07-09-20-59-01
|.//apc.EQs3Up| CREATE 2014-07-09-20-59-01
|.//apc.EQs3Up| MODIFY 2014-07-09-20-59-01
|.//apc.EQs3Up| DELETE 2014-07-09-20-59-01
|.//apc.IpNU5o| CREATE 2014-07-09-20-59-01
|.//apc.IpNU5o| MODIFY 2014-07-09-20-59-01
|.//apc.QnNU5o| CREATE 2014-07-09-20-59-01
|.//apc.QnNU5o| MODIFY 2014-07-09-20-59-01
|.//apc.QnNU5o| DELETE 2014-07-09-20-59-01

As a side note, this trick works for seeing temporary table activity in MySQL's tmpdir as well.

  • Oh, thank you, this is really interesting! :) However, my main purpose is still unfullfilled: avoiding other users in a shared environment access other user's data :| Thank you though! :) Jul 15, 2014 at 11:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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