Speed and hosting
Poly Community draws its pages in PHP, as WordPress does, and keeps its data in tables of its own in the site database (their names start with poly_). Most of the time a page takes is WordPress, the theme and the other plugins of the site. This page says what a host needs, what the plugin does to keep pages fast, and what a page cache and an object cache add.
What it needs
-
PHP 8.1 or later and WordPress 7.2 or later.
-
PHP-FPM or LiteSpeed, recommended. Apache and Nginx both run PHP this way on most hosts. It lets Poly Community send the page first and do the rest after, such as notifications. Without it everything still works, a little slower. Settings → Advanced → Background jobs shows whether a site has it.
-
A system cron for the jobs, on a busy site. A cron entry that runs this every minute keeps a worker going for 55 seconds of each minute, and while it runs, pages leave the jobs to it:
wp --path=/path/to/wordpress poly-community queue work -
Opcache on, as nearly every host has it, so PHP does not read the code again on each request.
As a guide, a virtual server of 4 cores and 4 GB with 8 PHP workers draws a page of the community for a visitor in about 0.2 to 0.3 seconds.
How it keeps pages fast
Moving between pages is data, not pages. This is where most of the speed of Poly Community comes from, and every page that can move this way does.
- A tap does not load a new page. Every page of the menu, a member page and a post page has a file of its own, a static script the browser keeps. A tap builds the page from that file and asks the site one request for its data, what is in it now, and the page is drawn in place. WordPress draws no page for it.
- After the first page, the browser asks the site for data alone. In the background it fetches only static files, the page files and their templates, never a page.
- Back shows the page at once. Going back to a feed or to the members directory draws it from memory, as it stood, and asks once for its data when it may be out of date.
- Changes come as data too. Changes made by others reach the open pages ready to show, with nothing more asked of the site, as Live updates below says.
A page without a file of its own, such as an address with a query, is fetched whole and drawn in place. Moving between pages explains how it works, and how a block or a kit keeps it working.
- Background work waits for the answer to leave, as above.
- It works with page caches and object caches as the rest of this page says.
Live updates and the load on the server
Every open page of a member stays live. How it hears what is new decides most of the load a busy community puts on its server.
- On any host, an open page asks the site what is new every 10 seconds, and every 60 seconds while its tab is in the background (Settings → Advanced → Live updates). Each time is a full request to WordPress, which most of the time answers that nothing is new. On a typical server one takes about 0.2 seconds of a PHP worker, as other requests to the REST API do. Pages of visitors ask nothing.
- With WordPlus Cloud, an open page asks nothing while its connection is up, only once after it drops, for what it missed. The site works only when something changes: one request to WordPlus Cloud, sent after the member who made the change has the answer, however many pages show it.
With members looking at the community in their open tabs:
| Members with it open | Requests a minute, on any host | PHP workers busy all the time, on any host | With WordPlus Cloud |
|---|---|---|---|
| 50 | 300 | about 1 | none while the member is not using the page |
| 200 | 1,200 | about 4 | none while the member is not using the page |
| 1,000 | 6,000 | about 20 | none while the member is not using the page |
When something does change, both work the same: the change reaches the open pages as data, with the poll or over WordPlus Cloud, ready to show, and the page asks the site nothing more for it. The difference is all the asking in between.
A server with 8 PHP workers would spend all of them on these questions at about 400 members, before drawing a single page. A tab in the background asks six times less often, so real numbers fall between those and a sixth of them.
Page caches
A page cache keeps the HTML of a page and gives the same copy to the next visitor, without running WordPress. Poly Community works with these:
- Cache Enabler, the one with the fewest settings.
- WP Super Cache, with a permalink setting that ends with a slash, as Post name does (
/%postname%/). - W3 Total Cache, WP-Optimize and WP Fastest Cache.
- LiteSpeed Cache, on a LiteSpeed server. Set up the system cron above with it, so a post published later by the jobs reaches visitors within a minute.
It also tells Nginx Helper and WP Rocket which pages to drop. Autoptimize and the optimizer of LiteSpeed Cache, which combine and shrink scripts and styles, work with it too.
Logged-in members never get a kept page
A page drawn for someone logged in tells every cache not to keep it, and its REST answers are never kept. If a cache set to keep the pages of logged-in users gives one anyway, the page sees that it was drawn for someone else and fetches itself again past the cache. The sign-up page is never kept either.
Fresh pages for visitors
When something everyone may see changes, such as a public post, a reply, a space or a profile, Poly Community tells the cache to drop the pages that show it, and the next visitor gets them fresh. Likes, reactions, votes and counts wait until the kept page runs out, so give the cache a lifetime of an hour or less.
A developer can add another cache with the poly_community_purged action, which gives the addresses dropped, and change the addresses with the poly_community_purge_urls filter.
Object cache
WordPress keeps what it read from the database in memory for the length of one request. An object cache keeps it between requests, in Redis or Valkey, so the next page reads it from there instead of the database.
It is optional. It saves the database most of its queries, which helps most where the database is on another server or busy.
Setting it up
We run the free Redis Object Cache plugin with Valkey, and its paid version is not needed. With a Redis or Valkey server for the site, the settings go in wp-config.php:
define( 'WP_REDIS_HOST', '127.0.0.1' );
define( 'WP_REDIS_PORT', 6379 );
define( 'WP_REDIS_PASSWORD', 'the password of the server' );
define( 'WP_REDIS_PREFIX', 'example:' ); // one per site, when sites share a server
define( 'WP_REDIS_MAXTTL', 86400 );
define( 'WP_REDIS_GRACEFUL', true );
Then turn the cache on under Settings → Redis. The server needs little memory, a few megabytes at first. Give it a limit and let it drop the keys used least when full (maxmemory 128mb and maxmemory-policy allkeys-lru). It needs nothing on disk, as everything in it can be read again from the database.
When the cache server stops
Without WP_REDIS_GRACEFUL, every page of the site shows Error establishing a Redis connection the moment the cache server is gone, and the site stays down until the server is back. With it, the site goes on without the cache, a little slower.
Turning it off
Turn it off under Settings → Redis while the cache server still runs. PHP may go on loading the object cache file for a few minutes after it is removed, so if the server is already gone and pages still show the error, reload PHP (PHP-FPM, or the button of your host for it).
After changing the database outside WordPress
Restoring a backup, importing data or changing a table by hand leaves the cache holding the old values. Empty it afterwards:
wp --path=/path/to/wordpress cache flush
Measuring
- Query Monitor shows the queries and the time of each page.
?nocache=1at the end of the address of a community page asks for it past the page caches, as a page fresh from WordPress.