<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/apcu.setup.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'en',
  ),
  'this' => 
  array (
    0 => 'apcu.configuration.php',
    1 => 'Runtime Configuration',
    2 => 'Runtime Configuration',
  ),
  'up' => 
  array (
    0 => 'apcu.setup.php',
    1 => 'Installing/Configuring',
  ),
  'prev' => 
  array (
    0 => 'apcu.installation.php',
    1 => 'Installation',
  ),
  'next' => 
  array (
    0 => 'apcu.constants.php',
    1 => 'Predefined Constants',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'en',
    'path' => 'reference/apcu/ini.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="apcu.configuration" class="section">
 <h2 class="title">Runtime Configuration</h2>
 <p class="simpara">
The behaviour of these functions is affected by settings in <var class="filename">php.ini</var>.
</p>
 <p class="simpara">
  Although the default APCu settings are fine for many installations, serious
  users should consider tuning the following parameters.
 </p>
 <p class="simpara">
  There is one decision to be made configuring APCu.
  How much memory is going to be allocated to APCu.
  The ini directive that controls this is <code class="literal">apc.shm_size</code>
  Read the sections on this carefully below.
 </p>
 <p class="simpara">
  Once the server is running, the <code class="literal">apc.php</code> script that
  is bundled with the extension should be copied somewhere into the docroot and
  viewed with a browser as it provides a detailed analysis of the internal
  workings of APCu. If GD is enabled in PHP, it will even display some
  interesting graphs.</p>
  <p class="simpara">
  If APCu is working, the <code class="literal">Cache full count
  </code> number (on the left) will display the number of times the cache
  has reached maximum capacity and has had to evict entries to free up memory.
  During eviction, if <code class="literal">apc.ttl</code> was specified, APCu will first
  attempt to remove expired entries, i.e. entries whose TTL has either expired,
  or entries that have no TTL set and haven&#039;t been accessed in the last
  <code class="literal">apc.ttl</code> seconds. If <code class="literal">apc.ttl</code> was not set,
  or removing expired entries did not free up enough space, APCu will clear the
  entire cache.
  </p>
  <p class="simpara">
  The number of evictions should be minimal in a well-configured cache. If the
  cache is constantly being filled, and thusly forcefully freed, the resulting
  churning will have disparaging effects on script performance. The easiest way
  to minimize this number is to allocate more memory for APCu.
 </p>
 <p class="simpara">
  When APCu is compiled with mmap support (Memory Mapping), it will use only one
  memory segment, unlike when APCu is built with SHM (SysV Shared Memory) support
  that uses multiple memory segments. MMAP does not have a maximum limit like SHM
  does in <code class="literal">/proc/sys/kernel/shmmax</code>. In general MMAP support is
  recommended because it will reclaim the memory faster when the webserver is
  restarted and all in all reduces memory allocation impact at startup.
 </p>
 <p class="para">
  <table class="doctable table">
   <caption><strong>APCu configuration options</strong></caption>
   
    <thead>
     <tr>
      <th>Name</th>
      <th>Default</th>
      <th>Changeable</th>
      <th>Changelog</th>
     </tr>

    </thead>

    <tbody class="tbody">
     <tr>
      <td><a href="apcu.configuration.php#ini.apcu.enabled" class="link">apc.enabled</a></td>
      <td>1</td>
      <td><strong><code><a href="info.constants.php#constant.ini-system">INI_SYSTEM</a></code></strong></td>
      <td class="empty">&nbsp;</td>
     </tr>

     <tr>
      <td><a href="apcu.configuration.php#ini.apcu.shm-segments" class="link">apc.shm_segments</a></td>
      <td>1</td>
      <td><strong><code><a href="info.constants.php#constant.ini-system">INI_SYSTEM</a></code></strong></td>
      <td class="empty">&nbsp;</td>
     </tr>

     <tr>
      <td><a href="apcu.configuration.php#ini.apcu.shm-size" class="link">apc.shm_size</a></td>
      <td>&quot;32M&quot;</td>
      <td><strong><code><a href="info.constants.php#constant.ini-system">INI_SYSTEM</a></code></strong></td>
      <td class="empty">&nbsp;</td>
     </tr>

     <tr>
      <td><a href="apcu.configuration.php#ini.apcu.entries-hint" class="link">apc.entries_hint</a></td>
      <td>512 * apc.shm_size</td>
      <td><strong><code><a href="info.constants.php#constant.ini-system">INI_SYSTEM</a></code></strong></td>
      <td>Prior to APcu 5.1.25, the default was 4096</td>
     </tr>

     <tr>
      <td><a href="apcu.configuration.php#ini.apcu.ttl" class="link">apc.ttl</a></td>
      <td>0</td>
      <td><strong><code><a href="info.constants.php#constant.ini-system">INI_SYSTEM</a></code></strong></td>
      <td class="empty">&nbsp;</td>
     </tr>

     <tr>
      <td><a href="apcu.configuration.php#ini.apcu.gc-ttl" class="link">apc.gc_ttl</a></td>
      <td>3600</td>
      <td><strong><code><a href="info.constants.php#constant.ini-system">INI_SYSTEM</a></code></strong></td>
      <td class="empty">&nbsp;</td>
     </tr>

     <tr>
      <td><a href="apcu.configuration.php#ini.apcu.mmap-file-mask" class="link">apc.mmap_file_mask</a></td>
      <td>NULL</td>
      <td><strong><code><a href="info.constants.php#constant.ini-system">INI_SYSTEM</a></code></strong></td>
      <td class="empty">&nbsp;</td>
     </tr>

     <tr>
      <td><a href="apcu.configuration.php#ini.apcu.slam-defense" class="link">apc.slam_defense</a></td>
      <td>0</td>
      <td><strong><code><a href="info.constants.php#constant.ini-system">INI_SYSTEM</a></code></strong></td>
      <td class="empty">&nbsp;</td>
     </tr>

     <tr>
      <td><a href="apcu.configuration.php#ini.apcu.enable-cli" class="link">apc.enable_cli</a></td>
      <td>0</td>
      <td><strong><code><a href="info.constants.php#constant.ini-system">INI_SYSTEM</a></code></strong></td>
      <td class="empty">&nbsp;</td>
     </tr>

     <tr>
      <td><a href="apcu.configuration.php#ini.apcu.use-request-time" class="link">apc.use_request_time</a></td>
      <td>0</td>
      <td><strong><code><a href="info.constants.php#constant.ini-all">INI_ALL</a></code></strong></td>
      <td>Prior to APCu 5.1.19, the default was <code class="literal">1</code>.</td>
     </tr>

     <tr>
      <td><a href="apcu.configuration.php#ini.apcu.serializer" class="link">apc.serializer</a></td>
      <td>&quot;php&quot;</td>
      <td><strong><code><a href="info.constants.php#constant.ini-system">INI_SYSTEM</a></code></strong></td>
      <td>Prior to APCu 5.1.15, the default was <code class="literal">&quot;default&quot;</code>.</td>
     </tr>

     <tr>
      <td><a href="apcu.configuration.php#ini.apcu.coredump-unmap" class="link">apc.coredump_unmap</a></td>
      <td>0</td>
      <td><strong><code><a href="info.constants.php#constant.ini-system">INI_SYSTEM</a></code></strong></td>
      <td class="empty">&nbsp;</td>
     </tr>

     <tr>
      <td><a href="apcu.configuration.php#ini.apcu.preload-path" class="link">apc.preload_path</a></td>
      <td>NULL</td>
      <td><strong><code><a href="info.constants.php#constant.ini-system">INI_SYSTEM</a></code></strong></td>
      <td class="empty">&nbsp;</td>
     </tr>

    </tbody>
   
  </table>

  For further details and definitions of the
INI_* modes, see the <a href="configuration.changes.modes.php" class="xref">Where a configuration setting may be set</a>.
 </p>

 <p class="para">Here&#039;s a short explanation of
the configuration directives.</p>

 <dl>
  
   <dt id="ini.apcu.enabled">
    <code class="parameter">apc.enabled</code>
    <span class="type"><a href="language.types.boolean.php" class="type bool">bool</a></span>
   </dt>
   <dd>
    <span class="simpara">
     <code class="literal">apc.enabled</code> can be set to 0 to disable APC. This is
     primarily useful when APC is statically compiled
     into PHP, since there is no other way to disable
     it (when compiled as a DSO, the <code class="literal">extension</code>
     line in <code class="literal">php.ini</code> can just be commented-out).
    </span>
   </dd>
  
  
   <dt id="ini.apcu.shm-segments">
    <code class="parameter">apc.shm_segments</code>
    <span class="type"><a href="language.types.integer.php" class="type int">int</a></span>
   </dt>
   <dd>
    <span class="simpara">
     The number of shared memory segments to allocate
     for the compiler cache. If APC is running out of
     shared memory but <code class="literal">apc.shm_size</code>
     is set as high as the system allows, raising
     this value might prevent APC from exhausting its memory.
    </span>
   </dd>
  
  
   <dt id="ini.apcu.shm-size">
    <code class="parameter">apc.shm_size</code>
    <span class="type"><a href="language.types.string.php" class="type string">string</a></span>
   </dt>
   <dd>
    <span class="simpara">
     The size of each shared memory segment given by a shorthand notation as
     described in <a href="faq.using.php#faq.using.shorthandbytes" class="link">this FAQ</a>.
     By default, some systems (including most BSD
     variants) have very low limits on the size of a
     shared memory segment.
    </span>
   </dd>
  
  
   <dt id="ini.apcu.entries-hint">
    <code class="parameter">apc.entries_hint</code>
    <span class="type"><a href="language.types.integer.php" class="type int">int</a></span>
   </dt>
   <dd>
    <span class="simpara">
     A &quot;hint&quot; about the number of distinct variables that might be stored.
     Set to zero or omit if not sure.
    </span>
   </dd>
  
  
   <dt id="ini.apcu.ttl">
    <code class="parameter">apc.ttl</code>
    <span class="type"><a href="language.types.integer.php" class="type int">int</a></span>
   </dt>
   <dd>
    <span class="simpara">
     Consider cache entries without an explicit TTL to be
     expired if they have not been accessed in this many
     seconds. Effectively, this allows such entries to be
     removed opportunistically during a cache insert, or
     prior to a full expunge. Note that because removal is
     opportunistic, entries can still be readable even if
     they are older than <code class="literal">apc.ttl</code> seconds.
     This setting has no effect on cache entries that have
     an explicit TTL specified.
    </span>
   </dd>
  
  
   <dt id="ini.apcu.gc-ttl">
    <code class="parameter">apc.gc_ttl</code>
    <span class="type"><a href="language.types.integer.php" class="type int">int</a></span>
   </dt>
   <dd>
    <span class="simpara">
     The number of seconds that a cache entry may
     remain on the garbage-collection list after being removed or invalidated.
     Entries are eligible for removal if their reference count is zero,
     or they exceed this time limit.
     If set to <code class="literal">0</code>, time-based cleanup is disabled,
     and entries are only removed when their reference count drops to zero.
    </span>
   </dd>
  
  
   <dt id="ini.apcu.mmap-file-mask">
    <code class="parameter">apc.mmap_file_mask</code>
    <span class="type"><a href="language.types.string.php" class="type string">string</a></span>
   </dt>
   <dd>
    <span class="simpara">
     If compiled with MMAP support by using <code class="literal">--enable-mmap</code>
     this is the mktemp-style file_mask to pass to the
     mmap module for determining whether your mmap&#039;ed memory
     region is going to be file-backed or shared memory
     backed.  For straight file-backed mmap, set it to
     something like <code class="literal">/tmp/apc.XXXXXX</code>
     (exactly 6 <code class="literal">X</code>s).
     To use POSIX-style shm_open/mmap put a <code class="literal">.shm</code>
     somewhere in your mask.  e.g. <code class="literal">/apc.shm.XXXXXX</code>
     You can also set it to <code class="literal">/dev/zero</code> to use your
     kernel&#039;s <code class="literal">/dev/zero</code> interface to anonymous mmap&#039;ed
     memory. Leaving it undefined will force an anonymous mmap.
    </span>
   </dd>
  
  
   <dt id="ini.apcu.slam-defense">
    <code class="parameter">apc.slam_defense</code>
    <span class="type"><a href="language.types.boolean.php" class="type bool">bool</a></span>
   </dt>
   <dd>
    <span class="simpara">
     On very busy servers whenever you start the server or
     modify files you can create a race of many processes
     all trying to cache the same file at the same time.
     Setting <code class="literal">apc.slam_defense</code> to <code class="literal">1</code>
     can help prevent multiple processes from caching the
     same file simultaneously by introducing a probability
     mechanism. If the same key is attempted to be cached
     within a short period by different processes, it skips
     the caching for the current process to mitigate potential
     cache slams.
    </span>
   </dd>
  
  
   <dt id="ini.apcu.enable-cli">
    <code class="parameter">apc.enable_cli</code>
    <span class="type"><a href="language.types.integer.php" class="type int">int</a></span>
   </dt>
   <dd>
    <span class="simpara">
     Mostly for testing and debugging.  Setting this enables APC
     for the CLI version of PHP.  Under normal circumstances, it is
     not ideal to create, populate and destroy the APC cache on every
     CLI request, but for various test scenarios it is useful to be
     able to enable APC for the CLI version of PHP easily.
    </span>
   </dd>
  
  
   <dt id="ini.apcu.serializer">
    <code class="parameter">apc.serializer</code>
    <span class="type"><a href="language.types.string.php" class="type string">string</a></span>
   </dt>
   <dd>
    <span class="simpara">
     Used to configure APC to use a third party serializer.
    </span>
   </dd>
  
  
   <dt id="ini.apcu.coredump-unmap">
    <code class="parameter">apc.coredump_unmap</code>
    <span class="type"><a href="language.types.boolean.php" class="type bool">bool</a></span>
   </dt>
   <dd>
    <span class="simpara">
     Enables APC handling of signals, such as SIGSEGV, that write
     core files when signaled. When these signals are received,
     APC will attempt to unmap the shared memory segment in order
     to exclude it from the core file. This setting may improve
     system stability when fatal signals are received and a large
     APC shared memory segment is configured.
    </span>
    <div class="warning"><strong class="warning">Warning</strong>
     <p class="simpara">
      This feature is potentially dangerous. Unmapping the shared
      memory segment in a fatal signal handler may cause undefined
      behaviour if a fatal error occurs.
     </p>
    </div>
    <blockquote class="note"><p><strong class="note">Note</strong>: 
     <span class="simpara">
      Although some kernels may provide a facility to ignore various
      types of shared memory when generating a core dump file, these
      implementations may also ignore important shared memory segments
      such as the Apache scoreboard.
     </span>
    </p></blockquote>
   </dd>
  
  
   <dt id="ini.apcu.preload-path">
    <code class="parameter">apc.preload_path</code>
    <span class="type"><a href="language.types.string.php" class="type string">string</a></span>
   </dt>
   <dd>
    <span class="simpara">
     Optionally, set a path to the directory that APC will load
     cache data at startup.
    </span>
   </dd>
  

  
   <dt id="ini.apcu.use-request-time">
    <code class="parameter">apc.use_request_time</code>
    <span class="type"><a href="language.types.boolean.php" class="type bool">bool</a></span>
   </dt>
   <dd>
    <span class="simpara">
     Use the <abbr title="Server Application Programming Interface">SAPI</abbr> request start time for
     <abbr>TTL</abbr>.
    </span>
   </dd>
  
 </dl>
</div><?php manual_footer($setup); ?>