Get the most out of your Centmin Mod LEMP stack
Become a Member

Xenforo Possible the fast_cgi cache on xenforo 2.1.x ?

Discussion in 'Forum software usage' started by negative, Feb 1, 2020.

  1. negative

    negative Active Member

    384
    46
    28
    Apr 11, 2015
    Ratings:
    +90
    Local Time:
    9:54 PM
    1.9.10
    10.1.11
    Hello

    I was tried it before while using the xenforo 1.5 and disabled later because of some caching problem between guest and users actually.

    Here is original article link from @rdan

    https://xenforo.com/community/threa...fastcgi_cache-full-page-guest-caching.110806/

    Anyway, i'm looking the use nginx fastcgi cache feature for xenforo 2.1.x too ?

    Firstly, i didn't find any add-on for like logged in cookie. And then, need other settings for nginx.

    Is it possible? Or is there any way to make it as usable ?

    Actually, i'm using the guest page caching feature of the xenforo 2.1 and redis cache etc. too but anyway, it will be better if i cache the my pages like up to 3 hours for my guests only with nginx fastcgi cache. Because, i must decrease the FID time a bit on my mobile pages, they are around 320-330 now, and google shows error (as slow all thread pages for mobile) and fastcgi cache will be decrease that a bit more i thought (they should be under of the 300)

    I'm looking the way to using full fastcgi cache on board.

    Thanks
     
  2. eva2000

    eva2000 Administrator Staff Member

    44,417
    10,144
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +15,692
    Local Time:
    4:54 AM
    Nginx 1.17.x
    MariaDB 5.5/10.x
    PHP-FPM fastcgi_cache for Xenforo 2.1 is pretty much same as for 1.5 just the cookie is different = xf_user and maybe some of admin or paths you want to exclude from cache by default. I suggest you set a test VPS server with test XF 2.1 install and keep testing PHP-FPM fastcgi_cache implementations in safely in confines of a test server without touching live forum's server until you figure it out.

    that problem might not be due to PHP-FPM fastcgi_cache but Xenforo 2.1 native guest full HTML page cache issue outlined at https://xenforo.com/community/threads/guest-page-caching.164816/. Disable XF 2.1 native guest page cache and see if it fixes your problem.
     
  3. rdan

    rdan Well-Known Member

    4,939
    1,179
    113
    May 25, 2014
    Ratings:
    +1,785
    Local Time:
    2:54 AM
    Mainline
    10.2
  4. rdan

    rdan Well-Known Member

    4,939
    1,179
    113
    May 25, 2014
    Ratings:
    +1,785
    Local Time:
    2:54 AM
    Mainline
    10.2
  5. nfn

    nfn New Member

    29
    0
    1
    Jun 28, 2015
    Ratings:
    +8
    Local Time:
    7:54 PM
    You can use lsws cache addon to do what you want, then map the cookies this way:

    Code:
    fastcgi_cache_path /dev/shm/nginx_cache levels=1:2 keys_zone=ngx_cache:500m inactive=60m;
    fastcgi_cache_key "$scheme$request_method$host$request_uri";
    
    map $http_cookie $cache_cookie {
      default 0;
      ~xf_lscxf_logged_in 1;
      ~xf_user 1;
      ~xf_session_admin 1;
    }
    
    map $request_method $cache_method {
      default 0;
      POST 1;
    }
    
    map $request_uri $cache_uri {
      default 1;
       ~^/threads/ 0;
       ~^/forums/ 0;
       ~^/attachments/ 0;
       ~^/css.php 0;
       ~^/$ 0;
    }
    and ...

    Code:
    location ~ [^/]\.php(/|$) {
        include conf.d/fpm_no_location.conf;
        fastcgi_cache ngx_cache;
        fastcgi_cache_valid 200 10m;
        fastcgi_ignore_headers Cache-Control Expires Set-Cookie;
        fastcgi_cache_lock on;
        fastcgi_cache_use_stale error timeout invalid_header updating http_500;
        fastcgi_no_cache $cache_cookie $cache_method $cache_uri;
        fastcgi_cache_bypass $cache_cookie $cache_method $cache_uri;
      }
     
  6. rdan

    rdan Well-Known Member

    4,939
    1,179
    113
    May 25, 2014
    Ratings:
    +1,785
    Local Time:
    2:54 AM
    Mainline
    10.2
    Nice, never thought that addon can do the job.
     
  7. negative

    negative Active Member

    384
    46
    28
    Apr 11, 2015
    Ratings:
    +90
    Local Time:
    9:54 PM
    1.9.10
    10.1.11
  8. negative

    negative Active Member

    384
    46
    28
    Apr 11, 2015
    Ratings:
    +90
    Local Time:
    9:54 PM
    1.9.10
    10.1.11
  9. rdan

    rdan Well-Known Member

    4,939
    1,179
    113
    May 25, 2014
    Ratings:
    +1,785
    Local Time:
    2:54 AM
    Mainline
    10.2
    Yeah it needs an addon but no available atm.
     
  10. rdan

    rdan Well-Known Member

    4,939
    1,179
    113
    May 25, 2014
    Ratings:
    +1,785
    Local Time:
    2:54 AM
    Mainline
    10.2
    Problem with that addon, already logged users before installing the addon will not have xf_lscxf_logged_in cookie.
    So their page would possible be cache?
     
  11. nfn

    nfn New Member

    29
    0
    1
    Jun 28, 2015
    Ratings:
    +8
    Local Time:
    7:54 PM
    @rdan logged user will never be cached.

    If one of these cookies (xf_lscxf_logged_in|xf_user|xf_session_admin) is present, the page won't be cached.
     
  12. rdan

    rdan Well-Known Member

    4,939
    1,179
    113
    May 25, 2014
    Ratings:
    +1,785
    Local Time:
    2:54 AM
    Mainline
    10.2
    Before installing this addon, logged members won't have those cookie.
     
  13. negative

    negative Active Member

    384
    46
    28
    Apr 11, 2015
    Ratings:
    +90
    Local Time:
    9:54 PM
    1.9.10
    10.1.11
    That is important point ..

    However, lsws cache add-on is for litespeed web server, we are using the nginx
     
  14. nfn

    nfn New Member

    29
    0
    1
    Jun 28, 2015
    Ratings:
    +8
    Local Time:
    7:54 PM
    No they don't, but they have xf_user, so page wont be cached.
     
  15. nfn

    nfn New Member

    29
    0
    1
    Jun 28, 2015
    Ratings:
    +8
    Local Time:
    7:54 PM
    I know that, but you must understand what it does and how it's setup to run with nginx.

    By default XF already sets xf_user and xf_session_admin cookies, this addon just make sure that if theses are not presente we always have xf_lscxf_logged_in.

    So, we know that whenever one of these cookies are present, page wont be cached because fastcgi_no_cache will have a value different from 0 (see map $http_cookie in my first post)

    But I would say that XF already does an excellent job with they page cache, so you won't have an huge performance benefit using fastcgi cache.
     
  16. rdan

    rdan Well-Known Member

    4,939
    1,179
    113
    May 25, 2014
    Ratings:
    +1,785
    Local Time:
    2:54 AM
    Mainline
    10.2
    I mean those users who do not check "Stay logged in" while logging in.
     
  17. rdan

    rdan Well-Known Member

    4,939
    1,179
    113
    May 25, 2014
    Ratings:
    +1,785
    Local Time:
    2:54 AM
    Mainline
    10.2
    Works great and implemented on this Forum.
     
  18. nfn

    nfn New Member

    29
    0
    1
    Jun 28, 2015
    Ratings:
    +8
    Local Time:
    7:54 PM
    Can you measure de performance difference?
     
  19. rdan

    rdan Well-Known Member

    4,939
    1,179
    113
    May 25, 2014
    Ratings:
    +1,785
    Local Time:
    2:54 AM
    Mainline
    10.2
    Maybe via webmaster tools download stats only.
    GA stats is abnormal.
     
  20. eva2000

    eva2000 Administrator Staff Member

    44,417
    10,144
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +15,692
    Local Time:
    4:54 AM
    Nginx 1.17.x
    MariaDB 5.5/10.x
    Actually PHP-FPM fastcgi_cache would perform much better than XF 2.1 native guest full page cache as it bypasses PHP and serves cache from Nginx. Native XF 2.1 native guest full page cache still goes through PHP for it's logic so doesn't bypass PHP. Anytime cache logic/routines need PHP, it will be slower compared to cache which totally bypasses PHP. This is in terms scalability i.e. high concurrent user requests i.e. throughput instead of latency response times.

    It's also why centmin.sh menu option 22 wordpress installer's, cache enabler wp plugin implementation is faster than others cache enabler implementations as I configured the advanced caching where logic is offloaded to Nginx instead of PHP. Out of box non-centmin mod cache enabler wp plugin installs would still go through PHP unlike Centmin Mod's cache enabler wp plugin config. It's also why centmin.sh menu option 22 wordpress based cache enabler full guest HTML page cache would have closer performance to redis nginx level and PHP-FPM fastcgi_cache based wordpress as all 3 caching methods bypass PHP entirely and served from Nginx level.