I have big data portions to cache in APC (normal file caching is too slow). apc_store
function always return false
for this amount of data:
I tried to do something like this:
ini_set('apc.max_file_size', '128M');
die(ini_get('apc.max_file_size'));
And the output is 1M
! It doesn't throw any error, but it simply doesn’t work. All other ini_sets I have (eg. memory_limit
) are working well, so it’s not permissions issue.
My APC info is:
Version 3.1.3p1
MMAP Support Enabled
MMAP File Mask no value
Locking type pthread mutex Locks
Revision $Revision: 286798 $
Build Date Apr 18 2010 06:56:17
and settings are:
apc.cache_by_default On
apc.canonicalize On
apc.coredump_unmap Off
apc.enable_cli Off
apc.enabled On
apc.file_md5 Off
apc.file_update_protection 2
apc.filters no value
apc.gc_ttl 3600
apc.include_once_override Off
apc.lazy_classes Off
apc.lazy_functions Off
apc.max_file_size 1M
apc.mmap_file_mask no value
apc.num_files_hint 1000
apc.preload_path no value
apc.report_autofilter Off
apc.rfc1867 Off
apc.rfc1867_freq 0
apc.rfc1867_name APC_UPLOAD_PROGRESS
apc.rfc1867_prefix upload_
apc.rfc1867_ttl 3600
apc.shm_segments 1
apc.shm_size 128
apc.stat On
apc.stat_ctime Off
apc.ttl 0
apc.use_request_time On
apc.user_entries_hint 4096
apc.user_ttl 0
apc.write_lock On
What should I set to allow caching such big data potions?
Following @Ugo Meda's comment, I want to share with you my solution of this problem. As he correctly pointed out, that I couldn't set APC settings (ie. apc.max_file_size
) via ini_set
. It simply returns false
while other settings (ie. memory_limit
) work well!
So the only thing I could do was to set it directly in apc.ini. Location of this file on Ubuntu is:
/etc/php5/conf.d/apc.ini
Sometimes your APC settings are in php.ini in [APC] section - location of this file on Ubuntu is:
/etc/php5/apache2/php.ini
If you can't find it, simply run this command:
find / -name apc.ini
If there is no such file (apc.ini) try to look for php.ini and [APC] section there:
find / -name php.ini
Once you find correct configuration file you are ready to edit it's options. I simply added this two lines there:
apc.shm_size=512
apc.max_file_size=128M
After editing, save it and simply restart your Apache (Ubuntu - /etc/init.d/apache2 restart
). If for some reason you can't run this command, or you don't have permissions to mentioned *.ini files, then add sudo command on the beginning of each command above.
One more note about apc.shm_size:
If version of your APC is lower than 3.1.4, then value of this config option must be written in the same format as I wrote (no 'M
' at the end). If your version is 3.1.4 or higher, then you need to specify it in this way: 512M
.
Source: http://e-mats.org/2010/10/apc_mmap-mmap-failed-cannot-allocate-memory/
@Ugo Meda's - thanks again for pointing this out to me!