Learn about Centmin Mod LEMP Stack today
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

    28,487
    6,469
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +9,583
    Local Time:
    5:00 AM
    Nginx 1.13.x
    MariaDB 5.5
    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 Moderator Staff Member

    666
    308
    63
    May 25, 2014
    Sheffield, UK
    Ratings:
    +419
    Local Time:
    8:00 PM
    1.7.1
    MariaDB 10
  3. eva2000

    eva2000 Administrator Staff Member

    28,487
    6,469
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +9,583
    Local Time:
    5:00 AM
    Nginx 1.13.x
    MariaDB 5.5
    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 Moderator Staff Member

    666
    308
    63
    May 25, 2014
    Sheffield, UK
    Ratings:
    +419
    Local Time:
    8:00 PM
    1.7.1
    MariaDB 10
    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
     
    • Like Like x 1
  5. eva2000

    eva2000 Administrator Staff Member

    28,487
    6,469
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +9,583
    Local Time:
    5:00 AM
    Nginx 1.13.x
    MariaDB 5.5
    is that with Fetch public templates as files enabled ? or disabled ?
     
  6. Matt

    Matt Moderator Staff Member

    666
    308
    63
    May 25, 2014
    Sheffield, UK
    Ratings:
    +419
    Local Time:
    8:00 PM
    1.7.1
    MariaDB 10
    upload_2014-5-29_9-52-55.png
     
    • Like Like x 1
  7. eva2000

    eva2000 Administrator Staff Member

    28,487
    6,469
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +9,583
    Local Time:
    5:00 AM
    Nginx 1.13.x
    MariaDB 5.5
    Thanks restarted memcached server and enabled to see what's going on :)

    Disabled APCu as it isn't doing anything with Xenforo heh
     
    • Like Like x 1
  8. BamaStangGuy

    BamaStangGuy Active Member

    465
    136
    43
    May 25, 2014
    Ratings:
    +179
    Local Time:
    2:00 PM
    • Like Like x 1
  9. eva2000

    eva2000 Administrator Staff Member

    28,487
    6,469
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +9,583
    Local Time:
    5:00 AM
    Nginx 1.13.x
    MariaDB 5.5
    Moving this thread over to Centmin Mod Insights forum so folks can see how a new PHP extension was added manually :)
     
    • Like Like x 2
  10. RoldanLT

    RoldanLT Well-Known Member

    3,812
    934
    113
    May 25, 2014
    Phillipines
    Ratings:
    +1,259
    Local Time:
    3:00 AM
    1.11
    10.2
    Happy to use Libmemcached also :)
     
  11. ethanpil

    ethanpil Active Member

    168
    47
    28
    Nov 8, 2015
    Ratings:
    +87
    Local Time:
    5:00 AM
    Has APCu support been abandoned? Some of us prefer APCu instead of memcached ;)
     
  12. eva2000

    eva2000 Administrator Staff Member

    28,487
    6,469
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +9,583
    Local Time:
    5:00 AM
    Nginx 1.13.x
    MariaDB 5.5
    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

    28,487
    6,469
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +9,583
    Local Time:
    5:00 AM
    Nginx 1.13.x
    MariaDB 5.5
    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
    • Like Like x 1
  14. eva2000

    eva2000 Administrator Staff Member

    28,487
    6,469
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +9,583
    Local Time:
    5:00 AM
    Nginx 1.13.x
    MariaDB 5.5
    Updated 1st post with separate APCu cache install instructions for PHP 5.x and PHP 7.x branches
     
    • Winner Winner x 1
  15. ahmed

    ahmed Member

    195
    14
    18
    Feb 21, 2017
    Ratings:
    +20
    Local Time:
    9:00 PM
  16. eva2000

    eva2000 Administrator Staff Member

    28,487
    6,469
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +9,583
    Local Time:
    5:00 AM
    Nginx 1.13.x
    MariaDB 5.5
    in future maybe but for opcode caching default PHP Zend Opcache is still fastest :)
     
  17. ahmed

    ahmed Member

    195
    14
    18
    Feb 21, 2017
    Ratings:
    +20
    Local Time:
    9:00 PM
  18. eva2000

    eva2000 Administrator Staff Member

    28,487
    6,469
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +9,583
    Local Time:
    5:00 AM
    Nginx 1.13.x
    MariaDB 5.5
    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 Member

    195
    14
    18
    Feb 21, 2017
    Ratings:
    +20
    Local Time:
    9:00 PM
    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).
     
    • Like Like x 1
  20. ahmed

    ahmed Member

    195
    14
    18
    Feb 21, 2017
    Ratings:
    +20
    Local Time:
    9:00 PM