PHP + APC: how to cache data up to 128M?

I have large pieces of data for caching in APC (normal file caching is too slow). The apc_store function always returns 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 conclusion is 1M ! It does not cause any errors, but it just does not work. All the other ini_sets that I have (e.g. memory_limit ) work well, so the problems are not resolved.

My APC info:

 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:

 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 needs to be done to enable caching of such large data potions?

+4
source share
1 answer

Following @Ugo Meda's comment, I want to share with you my solution to this problem. As he correctly pointed out, I could not set APC settings (i.e. apc.max_file_size ) via ini_set . It just returns false , while other settings (i.e. memory_limit ) work well!

So the only thing I could do was install it directly in apc.ini. Location of this file on Ubuntu:

 /etc/php5/conf.d/apc.ini 

Sometimes your APC settings are located in php.ini in the [APC] section - the location of this file on Ubuntu:

 /etc/php5/apache2/php.ini 

If you cannot find it, just run this command:

 find / -name apc.ini 

If there is no such file (apc.ini), try to find php.ini and [APC] there:

 find / -name php.ini 

Once you find the correct configuration file, you are ready to edit its parameters. I just added two lines there:

 apc.shm_size=512 apc.max_file_size=128M 

After editing, save it and just restart Apache (Ubuntu - /etc/init.d/apache2 restart ). If for some reason you cannot run this command or you do not have rights to the mentioned * .ini files, then add the sudo command at the beginning of each of the above commands.

One more note about apc.shm_size:

If your APC version is lower than 3.1.4, the value of this configuration parameter should be written in the same format as I wrote (" M " is not indicated at the end). If your version is 3.1.4 or higher, you need to specify it as follows: 512M .

Source: http://e-mats.org/2010/10/apc_mmap-mmap-failed-cannot-allocate-memory/

@Ugo Meda - thanks again for pointing this out!

+3
source

All Articles