Search code examples
phpapacheapc

active APC in php


I have installed APC PHP in my server. PHPinfo is showing it. But just got a question as I am a bit confused...

will new PHP requests coming to the server will start using APC automatically or does php codes also need to be modified to make use of APC ? Can you please provide some clues.

Thanks


Solution

  • If apc is present it will be used. Unless the default value of apc.enabled is False, check it in the phpinfo.

    If the enabled settings is OK the first apc usage will be tho opcode. Storing a "compiled" version of your php scripts. Now this behavior can be greatly ehanced by turning on several settings ofh apc (like avoiding to check for source code modifications at each file access).

    There is also a second big functionnality in APC which is using it as a persitence/cacche storage for your application. But theses things needs specific applications instructions in your application' as if you were using a datatabase. Check these functions.

    To really activate APC optimisations you should look at all the APC settings. apc.shm_size and apc.shm_segments are the most usefull to check settings for the size of the APC memory and are shared for all the virtulahosts. But after theses basics settings here are some of the things you should check for the virtualhost/application (where you would use php_value instructions)-- or in the global php.ini--, this is an extract of a production configuration:

    Note that you should understand each activated setting and read the documentation, else you will end up in loosing hours in development as your source code changes wont be read by php

    # Activate apc
    apc.enabled =1
    # Optimisation of include/require_once calls
    apc.include_once_override =1
    # transform paths in absolute ones (no effect if apc.stat is not 0),
    # files from stream wrappers (extended includes)
    # won't be cached if this is activated as they cannot be used with php's realpath()
    apc.canonicalize  =1  
    # In production set it to 0, then file changes won't be observed before 
    # apache is restarted,
    # significant boost, else file time is stated at each access (needed at 1 in dev)
    apc.stat =0
    # avoid problems with rsync or svn not modifying mtime but only ctime
    # so if you're in production set this to 0, like for the previous one 
    apc.stat_ctime =0  
    
    # deprecated option: apc.optimization not available anymore
    # apc.optimization =0  
    
    # inform apc on number of files of the application
    apc.num_files_hint =2000
    
    # inform apc on the number of cache variables
    apc.user_entries_hint =100
    
    # cache lifetime managmenent ----------------
    # time (s) we can stay on the cache even when the cache is full -- Cache full count --
    # that means Garbage Collector is never inactivating theses datas before this time is over
    # >0 -> old data could stay in the cache while new data want's to come, if no data is deprecated
    # 7200 -> entries older than 2 hours will be thrown to make some place
    # 0 -> emptying full cache when full
    apc.ttl =0
    apc.user_ttl =0
    # this one is the same but you should note this this prevent Garbage collecting 
    # after each source change.
    apc.gc_ttl =0
    
    # What to cache ? ----------------------------
    # could be used to prevent some caching on specific files
    # but it's better to cache often used files, isn't it? at least in production
    #apc.filters  ="-config.php-.ini"
    # default to 1M, files bigger than that won't be cached
    apc.max_file_size  ="5M"
    
    # various things -------------------------------
    # only one process caching a same file (beter than apc.slam_defense)
    php_fla apc.write_lock  =1  
    # prevents caching half written files (by cp for example) by waiting x seconds
    # for new files caching. set it to 0 if using only rsync or mv
    apc.file_update_protection  =2
    # newest versions of APC only
    # adding a lazy loading capabilities, so you can parse a lot of files
    # and only used things are cached
    #apc.lazy_functions =1
    #apc.lazy_classes  =1