Configuration (php.ini)

APCu's behavior is controlled by several php.ini directives. These are typically set in your main php.ini file or a loaded configuration file like apcu.ini.

Directive Default Changeable Description
apc.enabled 1 PHP_INI_SYSTEM Toggles APCu on or off. Set to 0 to disable the extension entirely.
apc.shm_size 32M PHP_INI_SYSTEM The size of the shared memory segment in megabytes (M) or gigabytes (G). This is the total memory available for caching.
apc.entries_hint 0 PHP_INI_SYSTEM A hint for the number of distinct variables to store. Set this to the approximate number of keys you expect to cache to optimize hash table performance. If 0, a default is calculated based on shm_size.
apc.ttl 0 PHP_INI_SYSTEM The default Time-To-Live (in seconds) for cache entries. If an entry is not accessed for this duration, it becomes a candidate for cleanup. 0 means no global TTL.
apc.gc_ttl 3600 PHP_INI_SYSTEM The number of seconds a cache entry can live in the garbage-collection list.
apc.smart 0 PHP_INI_SYSTEM Controls the aggressiveness of cache clearing when memory is full. A higher value makes full cache wipes more likely.
apc.enable_cli 0 PHP_INI_SYSTEM If 0 (default), APCu is disabled in the PHP CLI environment. Set to 1 to enable it for command-line scripts.
apc.slam_defense 0 PHP_INI_SYSTEM If non-zero, helps prevent cache slams (dog-piling) by dropping write attempts for the same key within a very short time window. Note: As of 5.1.14, this defaults to 0 (off) due to potential issues.
apc.use_request_time 0 PHP_INI_ALL If 1, uses the SAPI request start time for TTL calculations instead of the system time. Useful for deterministic testing.
apc.serializer php PHP_INI_SYSTEM Specifies the serializer to use for complex variables. Defaults to PHP's built-in serializer. Can be set to igbinary if the igbinary extension is installed.
apc.preload_path NULL PHP_INI_SYSTEM Specifies a directory to scan for .data files to preload into the cache on startup. (Not available in ZTS builds).
apc.coredump_unmap 0 PHP_INI_SYSTEM If 1, APCu will attempt to unmap the shared memory segment on a crash to prevent it from being included in a core dump.
apc.mmap_file_mask NULL PHP_INI_SYSTEM (If using mmap) An mktemp-style file mask for creating a file-backed memory map (e.g., /tmp/apc.XXXXXX). If NULL, uses anonymous mapping.
apc.mmap_hugepage_size 0 PHP_INI_SYSTEM (If using mmap on Linux) The size of hugepages to request for the shared memory segment. 0 disables explicit hugepage use.