Jump to content
gurkendoktor

Website performance with ProcessWire, nginx and fastcgi_cache

Recommended Posts

Hi, 

I don't know if this is the right section for this but I collected some thoughts and a kind of manual about how to increase the performance of your website under load with nginx and fastcgi_cache.

At best, this could be a kind of ProCache for nginx users, as not everyone is using Apache and thus not able to use ProCache on their sites.

Additionally, this solution comes with the benefit of server side mobile detection and selective caching. 

http://svn.matthiashaak.com/website-performance-with-processwire-nginx-and-fastcgi_cache/

Please let me know your thoughts or questions about this. Be aware however, that with this solution you end up serving static pages, so no hooks or PHP functions will be called. 

I am currently working on a module that eases the cache purging, so kindly be patient if you need this. "Wait, and thou shalt receive" :)

  • Like 12

Share this post


Link to post
Share on other sites

Great article, but it didn't worked without ignoring some headers:

fastcgi_ignore_headers "Cache-Control" "Expires" "Set-Cookie";
  • Like 2

Share this post


Link to post
Share on other sites

For some reason I didn't get notified about your post, but you're right with the headers. Depending on the rest of your config, you actually might need to add this line. Exactly this cost me 30 minutes today, I just couldn't get it to work on a new installation. Thanks for pointing this out.

As with the cookie, the "=" version should, according to the documentation, work - but yours will definitely work better. I personally removed this part, because for my use case it's enough to know whether I'm using the admin area or not. Anyway, I will also update this part. Thanks for you input. 

The clear cache module is also taking shape (way too slow for my taste, but I only have so much time…), and should be ready for a first test drive soon.

  • Like 4

Share this post


Link to post
Share on other sites

ok, whoever uses this and wants to test drive the purging module, here it is:

https://github.com/gurkendoktor/processwire_purge_fcgi_cache in branch develop

Just install it and you're good to go. I will prepare a README later.

Looking forward to feedback or if it makes any sense for anyone except me. 

Known issues:

* You will see errors if the page has not been cached yet

* You will see errors if no page at all has been cached

* The UI is still a bit of a mess

  • Like 2

Share this post


Link to post
Share on other sites

Hi gurkendoctor

Any plans on an update for your module? :-)

I've installed it a bit back, but I have issues with saving pages.. Maybe it's just me that setup Nginx wrong, but your module fails to purge the cache whenever I save a page, so I was looking to see if the module were updated, but it hasn't changed for a while.

Share this post


Link to post
Share on other sites

Hey, sorry for the long break here and on the module. I just moved to another country on another continent, and after 4 weeks I moved again in this city I'm living in now, so there were some tideous tasks that required more effort than I thought. I just picked up developing things and writing about stuff again, and will share any improvements on this module here.

However, many things haved changed in processwire itself since then, so I have to first read some docs to keep up with all of the things happening.

  • Like 2

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By MoritzLost
      Cacheable Placeholders
      This module allows you to have pieces of dynamic content inside cached output. This aims to solve the common problem of having a mostly cacheable site, but with pieces of dynamic output here and there.  Consider this simple example, where you want to output a custom greeting to the current user:
      <h1>Good morning, <?= ucfirst($user->name) ?></h1> This snippet means you can't use the template cache (at least for logged-in users), because each user has a different name. Even if 99% of your output is static, you can only cache the pieces that you know won't include this personal greeting. A more common example would be CSRF tokens for HTML forms - those need to be unique by definition, so you can't cache the form wholesale.
      This module solves this problem by introducing cacheable placeholders - small placeholder tokens that get replaced during every request. The replacement is done inside a Page::render hook so it runs during every request, even if the response is served from the template cache. So you can use something like this:
      <h1>Good morning, {{{greeting}}}</h1> Replacement tokens are defined with a callback function that produces the appropriate output and added to the module through a simple hook:
      // site/ready.php wire()->addHookAfter('CachePlaceholders::getTokens', function (HookEvent $e) { $tokens = $e->return; $tokens['greeting'] = [ 'callback' => function (array $tokenData) { return ucfirst(wire('user')->name); } ]; $e->return = $tokens; }); Tokens can also include parameters that are parsed and passed to the callback function. There are more fully annotated examples and step-by-step instructions in the README on Github!
      Features
      A simple and fast token parser that calls the appropriate callback and runs automatically. Tokens may include multiple named or positional parameters, as well as multi-value parameters. A manual mode that allows you to replace tokens in custom pieces of cached content (useful if you're using the $cache API). Some built-in tokens for common use-cases: CSRF-Tokens, replacing values from superglobals and producing random hexadecimal strings. The token format is completely customizable, all delimiters can be changed to avoid collisions with existing tag parsers or template languages. Links
      Github Repository & documentation Module directory (pending approval) If you are interested in learning more, the README is very extensive, with more usage examples, code samples and usage instructions!
    • By anttila
      I have a new server and wanted to use nginx. However, I have two ProcessWire websites which does not let me do anything. I'll get this error every time when I try to change something and sometimes when logging in. Deleted all caches already from ProcessWire and browser. This also happens after installing new ProcessWire and all directories were owned by www-data.
      I also have two working websites without any problems and all these four uses same kind of setting on nginx config. I don't understand why some of those working fine and some not.
      Running Debian 10, MariaDB 10.3.22, PHP 7.4, nginx 1.14.2
      This request was aborted because it appears to be forged. #0 /sites/clients/clientname/wire/modules/Process/ProcessPageTrash.module(49): ProcessWire\SessionCSRF->validate() #1 /sites/clients/clientname/wire/core/Wire.php(380): ProcessWire\ProcessPageTrash->___execute() #2 /sites/clients/clientname/wire/core/WireHooks.php(823): ProcessWire\Wire->_callMethod() #3 /sites/clients/clientname/wire/core/Wire.php(450): ProcessWire\WireHooks->runHooks() #4 /sites/clients/clientname/wire/core/ProcessController.php(337): ProcessWire\Wire->__call() #5 /sites/clients/clientname/wire/core/Wire.php(380): ProcessWire\ProcessController->___execute() #6 /sites/clients/clientname/wire/core/WireHooks.php(823): ProcessWire\Wire->_callMethod() #7 /sites/clients/clientname/wire/core/Wire.php(450): ProcessWire\WireHooks->runHooks() #8 /sites/clients/clientname/wire/core/admin.php(150): ProcessWire\Wire->__call() #9 /sites/clients/clientname/wire/modules/AdminTheme/AdminThemeDefault/controller.php(13): require('/sites/clients/...') #10 /sites/clients/clientname/site/templates/admin.php(15): require('/sites/clients/...') #11 /sites/clients/clientname/wire/core/TemplateFile.php(318): require('/sites/clients/...') #12 /sites/clients/clientname/wire/core/Wire.php(380): ProcessWire\TemplateFile->___render() #13 /sites/clients/clientname/wire/core/WireHooks.php(823): ProcessWire\Wire->_callMethod() #14 /sites/clients/clientname/wire/core/Wire.php(450): ProcessWire\WireHooks->runHooks() #15 /sites/clients/clientname/wire/modules/PageRender.module(536): ProcessWire\Wire->__call() #16 /sites/clients/clientname/wire/core/Wire.php(383): ProcessWire\PageRender->___renderPage() #17 /sites/clients/clientname/wire/core/WireHooks.php(823): ProcessWire\Wire->_callMethod() #18 /sites/clients/clientname/wire/core/Wire.php(450): ProcessWire\WireHooks->runHooks() #19 /sites/clients/clientname/wire/core/WireHooks.php(924): ProcessWire\Wire->__call() #20 /sites/clients/clientname/wire/core/Wire.php(450): ProcessWire\WireHooks->runHooks() #21 /sites/clients/clientname/wire/modules/Process/ProcessPageView.module(213): ProcessWire\Wire->__call() #22 /sites/clients/clientname/wire/core/Wire.php(383): ProcessWire\ProcessPageView->___execute() #23 /sites/clients/clientname/wire/core/WireHooks.php(823): ProcessWire\Wire->_callMethod() #24 /sites/clients/clientname/wire/core/Wire.php(450): ProcessWire\WireHooks->runHooks() #25 /sites/clients/clientname/index.php(55): ProcessWire\Wire->__call() #26 {main}  
    • By MoritzLost
      Process Cache Control
      This module provides a simple solution to clearing all your cache layers at once, and an extensible interface to perform various cache-related actions.
      The simple motivation behind this module was that I was tired of manually clearing caches in several places after deploying a change on a live site. The basic purpose of this module is a simple Clear all caches link in the Setup menu which clears out all caches, no matter where they hide. You can customize what exactly the module does through it's configuration menu:
      Expire or delete all cache entries in the database, or selectively clear caches by namespace ($cache API) Clear the the template render cache. Clear out specific folders inside your site's cache directory (/site/assets/cache) Clear the ProCache page render cache (if your site is using ProCache) Refresh version strings for static assets to bust client-side browser caches (this requires some setup, see the full documentation for details). This is the basic function of the module. However, you can also add different cache management action through the API and execute them through the module's interface. For this advanced usage, the module provides:
      An interface to see all available cache actions and execute them. A system log and logging output on the module page to see verify what the module is doing. A CacheControlTools class with utility functions to clear out different caches. An API to add cache actions, execute them programmatically and even modify the default action. Permission management, allowing you granular control over which user roles can execute which actions. The complete documentation can be found in the module's README.
      Plans for improvements
      If there is some interest in this, I plan to expand this to a more general cache management solution. I particular, I would like to add additional cache actions. Some ideas that came to mind:
      Warming up the template render cache for publicly accessible pages. Removing all active user sessions. Let me know if you have more suggestions!
      Links
      https://github.com/MoritzLost/ProcessCacheControl ProcessCacheControl in the Module directory CHANGELOG in the repository Screenshots


    • By verdeandrea
      Hello,
      I am using ProCache v3.1.8 on ProcessWire 3.0.96.
      Everything worked fine in the past, but today I noticed that the css file serverd by procache gives a 410 error. 
      The file is there, I checked.
      I deleted the cached files, I deleted the css file, I looked into the .htaccess file looking for some clues about this problem but nothing worked.
      The only way i can see my website correctly again is disabling ProCache. 
      Has anyone any clue on what could be the cause of the problem or on what should I do to fix it?
      Thanks!
    • By abdulqayyum
      Hy Processwire community,
      There are some problem in fileCompiler cache.
      when i change under the directory \site\templates\ it must change under the directory /site/assets/cache/FileCompiler/site/templates/
      but it does not update and functionality working with /site/assets/cache/FileCompiler/site/templates/ directory.
       
      In this case please suggest me how i clear fileCompiler cache?
      what i have to clear it manually?
      Thanks AbdulQayyum.
×
×
  • Create New...