Search code examples
phpoptimizationapc

What is the maximum size of a stored value for PHP APC?


To speed things up on my website I have stored small tables as arrays using APC which has sped up my queries significantly. One table in particular (which I still LEFT JOIN) has almost 3000 rows and I was wondering if it would be efficient to put this in an array and store using APC too? Or is it too large?

The other tables I stored had a maximum of 20 rows.


Solution

  • There a number of ini settings which will dictate the maximum size of the values you can store.

    A list of the APC specific directives can be found here. http://php.net/manual/en/apc.configuration.php

    Most pertinent to your question is:

    apx.max_file_size - Prevent files larger than this value from getting cached. Defaults to 1M.

    "Rows" don't do much to describe data in terms of size. It is not unreasonable though to cache thousands of "rows". You can get a better sense of the size of your array by serializing it and then using strlen()/mb_strlen(). You probably don't want to go much higher than one MB per file, but you could increase the total size/segments of shared memory available to APC as needed, dependent on available RAM.

    If you've fixed your index issues maybe you will determine this is not a good candidate for your cache. There are a few factors to consider when looking at what to cache... How often does the data change? Is it costly to fetch from DB / either slow or requested frequently?