Welcome to Centmin Mod Community
Become a Member

PHP-FPM Experimenting with APCu data only caching with PHP & Zend OpCache

Discussion in 'Centmin Mod Insights' started by eva2000, May 29, 2014.

  1. eva2000

    eva2000 Administrator Staff Member

    53,530
    12,134
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,677
    Local Time:
    8:23 AM
    Nginx 1.27.x
    MariaDB 10.x/11.4+
    With PHP 5.5 and using Zend OpCache, you only get PHP opcode caching and loose the user data caching features that other opcode cachers like APC Cache, Xcache had.

    So someone forked the APC Cache project and stripped the opcode caching features out resulting in only user data caching features as the sole purpose. APCu is that forked project at GitHub - krakjoe/apcu: APCu - APC User Cache.

    Xenforo's admin options -> performance has a setting to save public templates as files but it requires opcode cacher like APC Cache or Xcache. But as I am using PHP 5.5.12 with Zend OpCache there is no user data caching features available. So decided to try out APCu data caching on this forum to see how it goes.

    APCu Install on PHP 7.x



    Basic commands used to install APCu

    Code (Text):
    cd /svr-setup
    git clone https://github.com/krakjoe/apcu
    cd apcu
    /usr/local/bin/phpize
    ./configure --with-php-config=/usr/local/bin/php-config
    make -j2
    make install
    


    APCu Install on PHP 5.x



    Basic commands used to install APCu

    Code (Text):
    cd /svr-setup
    git clone -b PHP5 https://github.com/krakjoe/apcu
    cd apcu
    /usr/local/bin/phpize
    ./configure --with-php-config=/usr/local/bin/php-config
    make -j2
    make install
    


    APCu Upgrade Commands




    to upgrade
    Code (Text):
    cd /svr-setup/apcu
    git stash
    git pull
    make clean
    /usr/local/bin/phpize
    ./configure --with-php-config=/usr/local/bin/php-config
    make -j2
    make install
    


    Enable & Configure APCu Cache



    Commands to setup the apcu.ini file and APCu settings
    Code (Text):
    CONFIGSCANDIR='/etc/centminmod/php.d'
    touch ${CONFIGSCANDIR}/apcu.ini
    
    cat > "${CONFIGSCANDIR}/apcu.ini" <<EOF
    extension=apcu.so
      apc.enabled=1
      apc.shm_size=256M
      apc.ttl=7200
      apc.enable_cli=1
      apc.gc_ttl=3600
      apc.entries_hint=4096
      apc.slam_defense=1
      apc.serializer=igbinary
    EOF
    
    fpmrestart
    


    Code (Text):
    ls -lah ${CONFIGSCANDIR}
    total 36K
    drwxr-xr-x 2 root root 4.0K May 29 18:14 .
    drwxr-xr-x 3 root root 4.0K May 24 01:58 ..
    -rw-r--r-- 1 root root  177 May 29 18:21 apcu.ini
    -rw-r--r-- 1 root root   19 May 24 03:18 geoip.ini
    -rw-r--r-- 1 root root  252 May 24 03:18 igbinary.ini
    -rw-r--r-- 1 root root   21 May 24 03:18 imagick.ini
    -rw-r--r-- 1 root root  115 May 24 03:18 memcached.ini
    -rw-r--r-- 1 root root   78 May 24 03:18 memcache.ini
    -rw-r--r-- 1 root root  382 May 24 03:23 zendopcache.ini


    Code (Text):
    php --ri apcu                          
    
    apcu
    
    APCu Support => Enabled
    Version => 4.0.11
    APCu Debugging => Disabled
    MMAP Support => Enabled
    MMAP File Mask =>  
    Serialization Support => php, igbinary
    Revision => $Revision: 328290 $
    Build Date => Jul 29 2016 20:17:07
    
    Directive => Local Value => Master Value
    apc.enabled => On => On
    apc.shm_segments => 1 => 1
    apc.shm_size => 256M => 256M
    apc.entries_hint => 4096 => 4096
    apc.gc_ttl => 3600 => 3600
    apc.ttl => 7200 => 7200
    apc.smart => 0 => 0
    apc.mmap_file_mask => no value => no value
    apc.enable_cli => On => On
    apc.slam_defense => On => On
    apc.rfc1867 => Off => Off
    apc.rfc1867_prefix => upload_ => upload_
    apc.rfc1867_name => APC_UPLOAD_PROGRESS => APC_UPLOAD_PROGRESS
    apc.rfc1867_freq => 0 => 0
    apc.rfc1867_ttl => 3600 => 3600
    apc.preload_path => no value => no value
    apc.coredump_unmap => Off => Off
    apc.use_request_time => On => On
    apc.serializer => igbinary => igbinary
    apc.writable => /tmp => /tmp
    


    Setup APCu admin stats file

    Code (Text):
    cd /svr-setup/apcu
    
    N=$RANDOM
    cp apc.php /usr/local/nginx/html/${N}_myapcu.php


    Then edit user/pass in /usr/local/nginx/html/${N}_myapcu.php

    apcu_stats00.png
     
    Last edited: Jul 30, 2016
  2. Matt

    Matt Well-Known Member

    926
    414
    63
    May 25, 2014
    Rotherham, UK
    Ratings:
    +669
    Local Time:
    11:23 PM
    1.5.15
    MariaDB 10.2
  3. eva2000

    eva2000 Administrator Staff Member

    53,530
    12,134
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,677
    Local Time:
    8:23 AM
    Nginx 1.27.x
    MariaDB 10.x/11.4+
    oh.. so can you use memcached as I have backend set to libmemcached for Xenforo config.php but the description only mentions opcode cacher ?

    edit: doh looks like APCu doesn't work with Xenforo for this, APCu php file shows zero files cached when enabled for public templates as files :(
     
  4. Matt

    Matt Well-Known Member

    926
    414
    63
    May 25, 2014
    Rotherham, UK
    Ratings:
    +669
    Local Time:
    11:23 PM
    1.5.15
    MariaDB 10.2
    This is my set up:

    Code:
    PHP 5.5.12 (cli) (built: May 25 2014 19:50:03)
    Copyright (c) 1997-2014 The PHP Group
    Zend Engine v2.5.0, Copyright (c) 1998-2014 Zend Technologies
        with Zend OPcache v7.0.4-dev, Copyright (c) 1999-2014, by Zend Technologies
    PHP:
    $config['cache']['enabled'] = true;
    $config['cache']['frontend'] = 'Core';
    $config['cache']['frontendOptions']['cache_id_prefix'] = 'mattw_';
    $config['cache']['frontendOptions']['automatic_serialization'] = true;
    $config['cache']['cacheSessions'] = true;
    $config['cache']['backend']='Libmemcached';
    $config['cache']['backendOptions']=array(
            
    'compression'=>false,
            
    'servers' => array(
                    array(
                            
    'host'=>'127.0.0.1',
                            
    'port'=>'11211',
                            
    'persistent' => 'true'
                    
    )
          )
    );
    All the backend stuff goes into Memcached (libmemcached), and the OPCaching is working with ZendOpcache

    upload_2014-5-29_9-47-43.png

    All the bdcache stuff is sitting in Memcached as that uses the backend options.
    upload_2014-5-29_9-49-44.png
     
  5. eva2000

    eva2000 Administrator Staff Member

    53,530
    12,134
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,677
    Local Time:
    8:23 AM
    Nginx 1.27.x
    MariaDB 10.x/11.4+
    is that with Fetch public templates as files enabled ? or disabled ?
     
  6. Matt

    Matt Well-Known Member

    926
    414
    63
    May 25, 2014
    Rotherham, UK
    Ratings:
    +669
    Local Time:
    11:23 PM
    1.5.15
    MariaDB 10.2
    upload_2014-5-29_9-52-55.png
     
  7. eva2000

    eva2000 Administrator Staff Member

    53,530
    12,134
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,677
    Local Time:
    8:23 AM
    Nginx 1.27.x
    MariaDB 10.x/11.4+
    Thanks restarted memcached server and enabled to see what's going on :)

    Disabled APCu as it isn't doing anything with Xenforo heh
     
  8. BamaStangGuy

    BamaStangGuy Active Member

    668
    192
    43
    May 25, 2014
    Ratings:
    +272
    Local Time:
    5:23 PM
  9. eva2000

    eva2000 Administrator Staff Member

    53,530
    12,134
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,677
    Local Time:
    8:23 AM
    Nginx 1.27.x
    MariaDB 10.x/11.4+
    Moving this thread over to Centmin Mod Insights forum so folks can see how a new PHP extension was added manually :)
     
  10. rdan

    rdan Well-Known Member

    5,439
    1,398
    113
    May 25, 2014
    Ratings:
    +2,187
    Local Time:
    6:23 AM
    Mainline
    10.2
    Happy to use Libmemcached also :)
     
  11. ethanpil

    ethanpil Active Member

    173
    55
    28
    Nov 8, 2015
    Ratings:
    +101
    Local Time:
    8:23 AM
    Has APCu support been abandoned? Some of us prefer APCu instead of memcached ;)
     
  12. eva2000

    eva2000 Administrator Staff Member

    53,530
    12,134
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,677
    Local Time:
    8:23 AM
    Nginx 1.27.x
    MariaDB 10.x/11.4+
    pretty much has been for centmin mod though you can still follow above 1st post manual install if you want APCu. Though you'd need for your web app to support APCu
     
  13. eva2000

    eva2000 Administrator Staff Member

    53,530
    12,134
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,677
    Local Time:
    8:23 AM
    Nginx 1.27.x
    MariaDB 10.x/11.4+
    FYI, just updated APCu install instructions in 1st post :)

    but they seem to fail to compile :(
    Code (Text):
                                                                                                                        ^
    In file included from /svr-setup/apcu/apc.c:36:0:
    /svr-setup/apcu/apc_globals.h:44:5: error: unknown type name ‘zend_long’
         zend_long shm_segments;      /* number of shared memory segments to use */
         ^
    /svr-setup/apcu/apc_globals.h:45:5: error: unknown type name ‘zend_long’
         zend_long shm_size;          /* size of each shared memory segment (in MB) */
         ^
    /svr-setup/apcu/apc_globals.h:46:5: error: unknown type name ‘zend_long’
         zend_long entries_hint;      /* hint at the number of entries expected */
         ^
    /svr-setup/apcu/apc_globals.h:47:5: error: unknown type name ‘zend_long’
         zend_long gc_ttl;            /* parameter to apc_cache_create */
         ^
    /svr-setup/apcu/apc_globals.h:48:5: error: unknown type name ‘zend_long’
         zend_long ttl;               /* parameter to apc_cache_create */
         ^
    /svr-setup/apcu/apc_globals.h:49:2: error: unknown type name ‘zend_long’
      zend_long smart;             /* smart value */
      ^
    /svr-setup/apcu/apc.c:41:31: fatal error: zend_smart_str.h: No such file or directory
    #   include "zend_smart_str.h"
                                   ^
    compilation terminated.
    make: *** [apc.lo] Error 1


    edit: ah it's because APCu 5.x is PHP 7 only Is APCu-5.1.x not compatible with PHP-5.x? · Issue #171 · krakjoe/apcu · GitHub
     
    Last edited: Jul 30, 2016
  14. eva2000

    eva2000 Administrator Staff Member

    53,530
    12,134
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,677
    Local Time:
    8:23 AM
    Nginx 1.27.x
    MariaDB 10.x/11.4+
    Updated 1st post with separate APCu cache install instructions for PHP 5.x and PHP 7.x branches
     
  15. ahmed

    ahmed Active Member

    361
    49
    28
    Feb 21, 2017
    Ratings:
    +63
    Local Time:
    12:23 AM
  16. eva2000

    eva2000 Administrator Staff Member

    53,530
    12,134
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,677
    Local Time:
    8:23 AM
    Nginx 1.27.x
    MariaDB 10.x/11.4+
    in future maybe but for opcode caching default PHP Zend Opcache is still fastest :)
     
  17. ahmed

    ahmed Active Member

    361
    49
    28
    Feb 21, 2017
    Ratings:
    +63
    Local Time:
    12:23 AM
  18. eva2000

    eva2000 Administrator Staff Member

    53,530
    12,134
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,677
    Local Time:
    8:23 AM
    Nginx 1.27.x
    MariaDB 10.x/11.4+
    don't use LCache so can't help with that end. APCu should still install as per above guide so technically just install LCache after should work but you'd be on your own for that.
     
  19. ahmed

    ahmed Active Member

    361
    49
    28
    Feb 21, 2017
    Ratings:
    +63
    Local Time:
    12:23 AM
    I managed to enable it using your nice guide

    I think the author wants to say Apcu not Lcach

    WP LCache will repopulate the L1 cache (APCu) from the L2 cache (database).
     
  20. ahmed

    ahmed Active Member

    361
    49
    28
    Feb 21, 2017
    Ratings:
    +63
    Local Time:
    12:23 AM