We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 31654
    • 238 Posts
    Hello there!
    Would anyone like to help me integrate Varnish Cache into a MODx plugin?
    If you haven't heard or seen Varnish Cache then you should take a look here: https://www.varnish-cache.org/

    It really is amazing. From my real world testing I'm seeing page load times go from 2-3 secs to 2-3 ms (It really is that impressive).
    It's basically an application that sits between the web browser request & Apache. It's easy to install via YUM, It's open-source and the documentation is pretty good (and easy to understand).

    Because it serves pages from it's own cache we need to create a plugin that tells Varnish when a MODx resource has been updated and to refresh the Varnish cache.

    There are a few plugins for Wordpress & Drupal so maybe we can amend a plugin for our need in MODx?
    Here are a few examples I've found.

    https://github.com/mattiasgeniar/varnish-3.0-configuration-templates
    https://www.varnish-cache.org/trac/wiki/VCLExamples
      Web Development, Web Hosting & Search Engine Marketing by:

      Vitalized | UK
      w. www.vitalized.co.uk

      Website Design | Search Engine Marketing (SEM) | UK MODx web hosting, secure, fast & 100% MODx compatible

      Vitalized | Australia
      w. www.vitalized-australia.com.au

      Website Design | Search Engine Marketing (SEM) | Australian MODx web hosting, secure, fast & 100% MODx compatible
      • 39977
      • 11 Posts
      I am working on a project using Varnish as a load balance and cache in front of a pair or apache or nginx servers running Modx. Most of what I seen to date is about VCL only programming like your examples, that runs inside Varnish with Cookie filtration and TimeOut behavior only for cache persistence. Do you want to "smarten" the Varnish Cache replacement process and/or make Modx aware of the reverse proxy infront of it, and perhaps manage preloading and reloading?
        • 1841
        • 141 Posts
        Hi Si, did you ever get anywhere with this?
          • 34926
          • 87 Posts
          I use Varnish on our servers and the only rule I have is:

          sub vcl_recv {
          
                  ...
          
                  if (req.url ~ "^/manager/") {
                          return(pass);
                  }
          
                  ...
          
          
          }
          


          I haven't found the need to purge anything as of yet. I will write a plugin for this though, should be pretty simple.
            • 34926
            • 87 Posts
            I have submitted a plugin. The GitHub repo is at https://github.com/GoldCoastMedia/modx-varnish-purge .

            When its available I would appreciate any debugging info.
              • 12410
              • 353 Posts
              I actually tried to hook modx up with varnish but just kept getting the white screen of death when trying to install modx revo on it. ExpressionEngine didn't have the install issues with varnish on the same server using Ubuntu 12.04, php 5.3x, mysql 5.x. I was using EC2 on Amazon Web Services at the time. I dunno I figured varnish and modx were somewhat incompatible. if someone has hooked modx revo with varnish I would love to know the revo and varnish versions used and any workaround a. Varnish does rock alright in my low traffic testing of it. I suppose the question is how in terms of performance metrics does it compare with modx caching?
                • 1841
                • 141 Posts
                I can't see any reason why Varnish wouldn't work with Modx, it's just a case of making sure that caching still works and the Varnish cache is updated when modx is.
                  • 12410
                  • 353 Posts
                  Hi Gibbs,
                  What version of modx revo and varnish are you running please? How does the plugin work eg does it purge after an entry is updated/added or is it a manual purge button somewhere in manager interface?
                  I am planing to use it with revo 2.2.7, Ubuntu 12.10. ? What ssh command are you using to purge via ssh if needs be? Any other vcl info or quirky experiences with using varnish?
                  Thanks!!!!!

                  Updated
                  I have Modx Revo 227 running with Varnish now. I do get the error "Varnish Purge: Invalid method 'curl'. Please set the method to 'curl' or 'file_get_contents' via the System Settings." when clearing the Modx cache even though i have curl enabled: PHPINFO: cURL support enabled,cURL Information 7.27.0
                  Setting file_get_contents in Settings stops the error. Just wondering why curl aint working and is there a preference between both options ie whats the difference?

                  My vcl file is named main.vcl and I have copy and pasted the default.vcl contents (uncommented) into it and added your additions as per http://www.goldcoastmedia.co.uk/tools/modx-varnish-purge. I start varnish using varnishd -f /etc/varnish/main.vcl -s malloc,200M. Templates show fine but if I edit a resource and change the content text from say "hello world" to "goodbye", "goodbye" appears immediately. Shouldn't "hello world" appear until such time as I clear the cache or until a specific time lapse? Or does an edit to an entry auto purge the content?

                  Would be great to understand this better. my response header is below

                  Thanks

                  Server: Apache/2.2.22 (Ubuntu)
                  
                  x-powered-by: PHP/5.4.14-1~quantal+1
                  
                  Expires: Thu, 19 Nov 1981 08:52:00 GMT
                  
                  Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
                  
                  Pragma: no-cache
                  
                  Vary: Accept-Encoding
                  
                  Content-Encoding: gzip
                  
                  Content-Type: text/html; charset=UTF-8
                  
                  Content-Length: 135
                  
                  Accept-Ranges: bytes
                  
                  Date: Sat, 11 May 2013 15:34:47 GMT
                  
                  X-Varnish: 690407157
                  
                  Age: 0
                  
                  Via: 1.1 varnish
                  
                  Connection: keep-alive
                  
                  
                  200 OK
                  [ed. note: howster last edited this post 11 years ago.]
                    • 34926
                    • 87 Posts
                    Saving a document clears the cache for that specific page. I will add some more settings so that can be changed and look into why cURL isn't working.

                    Edit: The source code is very small and basic if you are interested. See https://github.com/GoldCoastMedia/modx-varnish-purge/blob/master/core/components/varnishpurge/varnishpurge.class.php
                      • 40385
                      • 75 Posts
                      Sorry for bumping this thread...but I am running MODx with Varnish and Nginx and only my static resources are being served from the Varnish cache. All other requests are having the header age = 0 which means they are not served from the Varnish cache. I suspect a cookie being the problem.

                      How did you guys handle this? [ed. note: paul_kemp last edited this post 9 years, 2 months ago.]