[title sub="Written by Chris Graham"]Composr Tutorial: Website Health[/title]

This tutorial will cover some aspects of keeping your website running smoothly.

[contents]decimal,lower-alpha[/contents]

[title="2"]Health Check[/title]

[media width="150" description="The Health Check screen" float="right"]data_custom/images/docs/tut_website_health/health_check.png[/media]
{!DOC_HEALTH_CHECK}

On the modern advanced web there is too much to keep in mind to check. All kinds of things could go wrong without you noticing, which could be embarrassing.
For example, what if:
1) Your outgoing e-mail goes down, breaking sign-ups
2) You forget to renew SSL
3) You forget to renew your domain name
4) A hacker takes control of the domain name and puts up a fake site
5) You accidentally block Google from accessing the website
All the above scenarios are auto-detectable.
In fact, you can detect problems stemming from many kinds of situation, including:
 - Quality issues after building a new site or theme
 - Software compatibility issues
 - Problems after a Composr upgrade
 - Hardware failure
 - Configuration issues
 - Lack of server capacity
 - Hack-attacks
 - Lack of routine maintenance or website up-keep

[title="3"]Operation[/title]

The Health Check can be run manually, or regularly run in the background (requires the system scheduler to be set up and for you to enable the "Health Check results" notification).

[title="3"]Configuration[/title]

There are a large number of configuration options available, under Admin Zone > Setup > Configuration > Health Check options.
This includes:
 - setting which pages to do deep scans of
 - calibrating the checks (setting thresholds)
 - configuring system scheduler checks, including the frequency, and which check sections to run

[title="3"]Tips[/title]

Make sure that your system scheduler (Cron call) is running the same PHP options as normal web requests, otherwise you may get spurious errors caused by differences in configuration.
System scheduler configuration is documented in the [page="_SEARCH:tut_configuration"]Basic configuration and getting started[/page] tutorial, and this includes sample commands that will share your [tt].user.ini[/tt] PHP configuration.

[title="3"]What if things break too badly for the Health Check to run?[/title]

There are a couple of approaches you can take to make sure you know if the health checker is itself down:
1) Feed an uptime checker into [tt]data/health_check.php[/tt] -- if it gives an HTTP error or the server does not respond, then you know Health Checks do not run (and a none-blank result shows there is a failing health check)
2) Enable the "Send full reports" option and check you receive the report each day (either manually or using some kind of third party e-mail scanning tool)

[title="3"]Philosophy[/title]

There is a vast amount to check when it comes to web development. Even though we check over 100 things, we can not realistically check everything under the scope of the Health Check.
The Health Check focuses on issues likely faced by end-users, and assumes Composr itself has been well programmed and tested.

The Composr ecosystem also has:
 - Automated testing. This is used for testing a huge array of low-level coding issues (too detailed for Health Check, possibly destructive, and requiring a lot of testing framework code). The tests are regularly run prior to Composr releases being made by the developers.
 - PHP-Info. The Health Check is not intended as a way to report on all your settings, only problematic ones. If you want to list some information about the PHP environment, use Admin Zone > Tools > PHP-Info to do this.
 - Cleanup tools. The Health Check does not attempt to "cleanup" caches and so on, only check for problems. The cleanup tools can be accessed from Admin Zone > Tools > Cleanup tools.
 - Staff checklist. The staff checklist (on the Admin Zone dashboard) has detailed information on staff actions that need performing. There is integration of this into the Health Check, but only at a high level.
 - External scanning tools. The Health Check doesn't itself directly ensure your website is perfectly optimised, it just focuses on the more major issues, and does sign-posting to other tools. The Health Check will link to various external tools that can perform detailed scans, such as gauging your SSL security.

Additionally you may want to check out Chris Graham's [url="Houndr project"]https://gitlab.com/occhris/houndr[/url] which can be used to remind yourself of manually things to check, or tell you when social media is not being updated.

[title="3"]Specific checks[/title]

[title="4"]"Upkeep \ PHP version" vs "Upkeep \ PHP version (if not distro default)"[/title]

The latter check is an alternative to the former check, and takes into account that some Linux distributions back-port fixes to their older bundled PHP versions. It will not check the version of PHP so long that it is installed as [tt]/usr/bin/php[/tt].
The latter check is only available on systems that support the [tt]which[/tt] command (essentially, on Linux).

Make sure you keep your server patched though! If you aren't on managed hosting and are not able to regularly schedule yourself to do manual updates, turn on automatic updates. There are real vulnerabilities coming out for software you'll be using all the time, so if you don't patch you'll be vulnerable.

[title="2"]PHP-Info[/title]

{!menus:DOC_PHPINFO}

PHP-Info can be reached from:
Admin Zone > Tools > PHP-Info / Server Checks

[title="2"]Failover mode[/title]

You may configure a special failover mode via the [tt]config_editor[/tt] script. This mode serves cached versions of page if your server seems to be failing. It is not a perfect system because:
1) it serves hits as guests
2) it can only work if the static cache is populated
3) it assumes that your server is only failing for performance/database reasons, not totally failed (however most failures in practice are like this)

However, it's still a great system because it lets your site content continue to be available even under massive load.

Failover can automatically fall into place based on a number of criteria.

Note that the failover status messages ([tt]failover_message_place_after[/tt] and [tt]failover_message_place_before[/tt] options) are put in place at the caching stage, not dynamically. So you would need to empty the static cache if you change these messages to something else.

Failover mode requires the PHP [tt]usleep[/tt] function not be disabled.

[title="2"]Cleanup tools[/title]

{!cleanup:DOC_CLEANUP_TOOLS}

The tools are divided into "De-cachers" and "Optimisers" (which don't all strictly involve optimising, some are for general other kinds of maintenance task).

[title="3"]Caches / De-cachers[/title]

[surround]
[media width="150" description="Disabling caches" float="right"]data_custom/images/docs/tut_website_health/cleanup_2.png[/media]
For performance reasons, Composr defines a number of caches. During normal operation of Composr, these caches should be unnoticeable; if things are being edited from outside Composr theoretically Composr will automatically pick up on it, but you may sometimes need to force a cache flush.

On a default install all recommended caches are enabled.

Some kinds of cache may be turned off in the configuration, but leaving them on gives vastly improved performance.

If you can identify a situation where you need to rebuild or empty a cache that should not exist, please report it as a bug.
[/surround]

[title="4"]Self-learning cache[/title]

The self-learning cache is quite a sophisticated cache mechanism to speed up Composr. It learns what resources are used by a page, and then bulk-loads them in the future.

The self-learning cache is most relevant when it comes to language strings. To avoid having to load up all the language files a page might use (language files are relatively monolithic, so inefficient to load), it will remember what strings are used by a page. Pages may use different strings when executed in different contexts, so the cache will always fall-back to loading the full language files if it has to, with those strings then also being added to the cache for the future. However, what if a page is referencing a string that does not exist? The self-learning cache would always be loading the full language files to try and hunt for it. This is why the cache also learns [i]what strings are used by a page but do not actually exist even in the full language files[/i]. A ramification of this is that if you are developing and add the strings later, you will need to clear out the self-learning cache for Composr to be able to pick up on the new strings.

[title="3"]Optimisers (advanced)[/title]

[surround]
[media width="150" description="The cleanup tools screen" float="right"]data_custom/images/docs/tut_website_health/cleanup_1.png[/media]
There are a number of optimisers:
 - [b]Find orphaned uploads[/b] -- find on-disk uploads that seem to no longer be referenced.
 - [b]Delete page access statistics[/b] -- remove old page statistics to reduce database usage.

Frankly most of these optimisers are not useful. We provide them for very rare situations, or for helping programmers manage complicated operations.

There are some additional tools for repairing database problems in the upgrader, see the [page="_SEARCH:tut_upgrade"]Performing an upgrade[/page] tutorial.
[/surround]

[title="2"]Broken URL scanning[/title]

There is a powerful broken link scanner at Admin Zone > Tools > Broken URL scanning.
This can check:
 - internal links
 - inbound (external) links to your site, if you configure Moz and/or Google Search Console from Admin Zone > Configuration > Composr API Options

We have the following kinds of broken URL checking across composr:
 - The broken URL scanning tool discussed here (works at the content level)
 - The Health Check, scanning specific URLs to see if the page there has broken URLs (works at the HTML level)
 - Comcode, URLs are checked when Comcode is parsed

[concepts
 1_key="Cache"                 1_value="A data store that contains pre-calculated results such that those results do not need to be calculated more than once; caches are designed to increase efficiency"
 2_key="PHP-Info"              2_value="PHP's configuration dump feature, accessible from within Composr"
]Concepts[/concepts]

[title="2"]See also[/title]

 - [page="_SEARCH:tut_webhosting"]Webhosting for Composr[/page] (including Composr minimum requirements)
 - [page="_SEARCH:tut_performance"]Optimising Performance[/page]
 - [page="_SEARCH:tut_security"]Security[/page]
 - [page="_SEARCH:tut_markup"]Guide to web technologies (including HTML, CSS, and JavaScript)[/page]
 - [page="_SEARCH:tut_disaster"]Disaster recovery[/page]
 - [page="_SEARCH:tut_seo"]Improving your search engine ranking[/page]
 - [page="_SEARCH:tut_email"]Understanding and configuring e-mail[/page]
 - [page="_SEARCH:tut_fringe"]Supplementary web technologies (media, social networking, etc)[/page]
 - [page="_SEARCH:tut_metadata"]Metadata[/page]
 - [page="_SEARCH:tut_cookies"]Introduction to Cookies and sessions (and JavaScript)[/page]
 - [page="_SEARCH:tut_accessibility"]Helping improve site accessibility for disabled users[/page]
 - [page="_SEARCH:sup_domain_names"]How domain names work[/page]
 - [page="_SEARCH:tut_upgrade"]Performing an upgrade[/page]
 - [page="_SEARCH:tut_telemetry"]Relaying Errors and Statistics to Composr[/page]
 - [url="Internet Archivee"]https://archive.org/[/url] (Find archived web pages that are no longer online)

{$SET,tutorial_tags,Maintenance,Webhosting,phpinfo,core_cleanup_tools,health_check,regular}{$SET,tutorial_add_date,Jul 2017}{$SET,tutorial_summary,This tutorial will cover some aspects of keeping your website running smoothly.}[block]main_tutorial_rating[/block]
