PHPackages                             silverstripe/environmentcheck - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. silverstripe/environmentcheck

ActiveSilverstripe-vendormodule[Utility &amp; Helpers](/categories/utility)

silverstripe/environmentcheck
=============================

Provides an API for building environment tests

4.1.0(9mo ago)35503.8k↓15.2%26[1 issues](https://github.com/silverstripe/silverstripe-environmentcheck/issues)13BSD-3-ClausePHPPHP ^8.3CI passing

Since Jan 28Pushed 7mo ago16 watchersCompare

[ Source](https://github.com/silverstripe/silverstripe-environmentcheck)[ Packagist](https://packagist.org/packages/silverstripe/environmentcheck)[ RSS](/packages/silverstripe-environmentcheck/feed)WikiDiscussions 4 Synced 1mo ago

READMEChangelog (10)Dependencies (7)Versions (62)Used By (13)

Silverstripe Environment Checker Module
=======================================

[](#silverstripe-environment-checker-module)

[![CI](https://github.com/silverstripe/silverstripe-environmentcheck/actions/workflows/ci.yml/badge.svg)](https://github.com/silverstripe/silverstripe-environmentcheck/actions/workflows/ci.yml)[![Silverstripe supported module](https://camo.githubusercontent.com/9b7e93d393a01f6d3091fb30983b870aa863ef076858115faaa1c74b995854ec/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f73696c7665727374726970652d737570706f727465642d3030373143342e737667)](https://www.silverstripe.org/software/addons/silverstripe-commercially-supported-module-list/)

This module adds an API for running environment checks to your API.

- `health/check` - A public URL that performs a quick check that this environment is functioning. This could be tied to a load balancer, for example.
- `dev/check` - An admin-only URL that performs a more comprehensive set of checks. This could be tied to a deployment system, for example.
- `dev/check/` - Check a specific suite (admin only)

Aren't these just unit tests?
-----------------------------

[](#arent-these-just-unit-tests)

Almost, but not really. Environment checks differ from unit tests in two important ways:

- **They test environment specific settings.** Unit tests are designed to use dummy data and mock interfaces to external system. Environment checks check the real systems and data that the given environment is actually connected to.
- **They can't modify data.** Because these checks will run using production databases, they can't go modifying the data in there. This is the biggest reason why we haven't used the same base class as a unit test for writing environment checks - we wanted to make it impossible to accidentally plug a unit test into the environment checker!

Installation
------------

[](#installation)

```
composer require silverstripe/environmentcheck
```

### Activating Directly

[](#activating-directly)

Register checks in your own `_config.php` - see the `_config.php` in this module for some defaults. Don't forget to either use a fully-qualified (namespaced) class name for `EnvironmentCheckSuite`, or `use` (import) the namespaced class first.

```
EnvironmentCheckSuite::register('health', 'DatabaseCheck', 'Can we connect to the database?');
EnvironmentCheckSuite::register('check', 'URLCheck("")', 'Is the homepage accessible?');
```

### Activating Via Config

[](#activating-via-config)

Register your checks on the `EnvironmentCheckSuite`. The same named check may be used multiple times.

```
SilverStripe\EnvironmentCheck\EnvironmentCheckSuite:
  registered_checks:
    db:
      definition: 'DatabaseCheck("Page")'
      title: 'Is the database accessible?'
    url:
      definition: 'URLCheck()'
      title: 'Is the homepage accessible?'
  registered_suites:
    check:
      - db
    health:
      - db
      - url
```

You can also disable checks configured this way. This is handy if you want to override a check imposed on your project by some other module. Just set the "state" property of the check to "disabled" like this:

```
SilverStripe\EnvironmentCheck\EnvironmentCheckSuite:
  registered_checks:
    db:
      state: disabled
```

Available checks
----------------

[](#available-checks)

- `DatabaseCheck`: Check that the connection to the database is working, by ensuring that the table exists and that the table contain some records.
- `URLCheck`: Check that a given URL is functioning, by default, the homepage.
- `HasFunctionCheck`: Check that the given function exists. This can be used to check that PHP modules or features are installed.
- `HasClassCheck`: Check that the given class exists. This can be used to check that PHP modules or features are installed.
- `FileWriteableCheck`: Check that the given file is writeable.
- `FileAccessibilityAndValidationCheck`: Check that a given file is accessible and optionally matches a given format.
- `FileAgeCheck`: Checks for the maximum age of one or more files or folders. Useful for files which should be frequently auto-generated, like static caches, as well as for backup files and folders.
- `ExternalURLCheck`: Checks that one or more URLs are reachable via HTTP.
- `SMTPConnectCheck`: Checks if the SMTP connection configured through PHP.ini works as expected.
- `SessionCheck`: Checks that a given URL does not generate a session.
- `CacheHeadersCheck`: Check cache headers in response for directives that must either be included or excluded as well checking for existence of ETag.
- `EnvTypeCheck`: Checks environment type, dev and test should not be used on production environments.

Monitoring Checks
-----------------

[](#monitoring-checks)

Checks will return an appropriate HTTP status code, so are easy to hook into common uptime montoring solutions like pingdom.com.

You can also have the environment checker email results with the following configuration:

```
SilverStripe\EnvironmentCheck\EnvironmentChecker:
  email_results: true
  to_email_address: support@test.com
  from_email_address: admin@test.com
```

Errors can be logged via the standard Silverstripe PSR-3 compatible logging. Each check will cause an individual log entry. You can choose to enable logging separately for warnings and errors, identified through the result of `EnvironmentCheck->check()`.

```
SilverStripe\EnvironmentCheck\EnvironmentChecker:
  log_results_warning: true
  log_results_error: true
```

Authentication
--------------

[](#authentication)

By default, accessing the `dev/check` URL will not require authentication on CLI and dev environments, but if you're trying to access it on a live or test environment, it will respond with a 401 HTTP status unless you're logged in as an administrator on the site.

You may wish to have an automated service check `dev/check` periodically, but not want to open it up for public access. You can enable basic authentication by defining the following in your environment (`.env` file):

```
ENVCHECK_BASICAUTH_USERNAME="test"
ENVCHECK_BASICAUTH_PASSWORD="password"

```

Now if you access `dev/check` in a browser it will pop up a basic auth popup, and if the submitted username and password match the ones defined the username and password defined in the environment, access will be granted to the page.

Adding more checks
------------------

[](#adding-more-checks)

To add more checks, you should put additional `EnvironmentCheckSuite::register` calls into your `_config.php`. See the `_config.php` file of this module for examples.

```
EnvironmentCheckSuite::register('check', 'HasFunctionCheck("curl_init")', "Does PHP have CURL support?");
EnvironmentCheckSuite::register('check', 'HasFunctionCheck("imagecreatetruecolor")', "Does PHP have GD2 support?");
```

The first argument is the name of the check suite. There are two built-in check suites, "health", and "check", corresponding to the `health/check` and `dev/check` URLs. If you wish, you can create your own check suites and execute them on other URLs. You can also add a check to more than one suite by passing the first argument as an array.

To test your own application, you probably want to write custom checks:

- Implement the `SilverStripe\EnvironmentCheck\EnvironmentCheck` interface
- Define the `check()` function, which returns a 2 element array:
    - The first element is one of `EnvironmentCheck::OK`, `EnvironmentCheck::WARNING`, `EnvironmentCheck::ERROR`, depending on the status of the check
    - The second element is a string describing the response.

Here is a simple example of how you might create a check to test your own code. In this example, we are checking that an instance of the `MyGateway` class will return "foo" when `call()` is called on it. Testing interfaces with 3rd party systems is a common use case for custom environment checks.

```
use SilverStripe\EnvironmentCheck\EnvironmentCheck;

class MyGatewayCheck implements EnvironmentCheck
{
    protected $checkTable;

    function check()
    {
        $g = new \MyGateway;

        $response = $g->call();
        $expectedResponse = 'foo';

        if($response == null) {
            return array(EnvironmentCheck::ERROR, "MyGateway didn't return a response");
        } else if($response != $expectedResponse) {
            return array(EnvironmentCheck::WARNING, "MyGateway returned unexpected response $response");
        }
        return array(EnvironmentCheck::OK, '');
    }
}
```

Once you have created your custom check class, don't forget to register it in a check suite

```
EnvironmentCheckSuite::register('check', 'MyGatewayCheck', 'Can I connect to the gateway?');
```

### Using other environment check suites

[](#using-other-environment-check-suites)

If you want to use the same UI as `health/check` and `dev/check`, you can create an `EnvironmentChecker` object. This class is a `RequestHandler` and so can be returned from an action handler. The first argument to the `EnvironmentChecker` constructor is the suite name. For example:

```
use SilverStripe\Control\Controller;

class DevHealth extends Controller
{
    function index()
    {
        $e = new EnvironmentChecker('health', 'Site health');
        return $e;
    }
}
```

If you wish to embed an environment check suite in another, you can use the following call:

```
$result = EnvironmentCheckSuite::inst('health')->run();
```

`$result` will contain a `EnvironmentCheckSuiteResult` object

- `$result->ShouldPass()`: Return a boolean of whether or not the tests passed.
- `$result->Status()`: The string "OK", "WARNING", or "ERROR", depending on the worst failure.
- `$result->Details()`: A `DataObjectSet` of details about the result of each check in the suite.

See `EnvironmentChecker.ss` to see how these can be used to build a UI.

Versioning
----------

[](#versioning)

This library follows [Semver](http://semver.org). According to Semver, you will be able to upgrade to any minor or patch version of this library without any breaking changes to the public API. Semver also requires that we clearly define the public API for this library.

All methods, with `public` visibility, are part of the public API. All other methods are not part of the public API. Where possible, we'll try to keep `protected` methods backwards-compatible in minor/patch versions, but if you're overriding methods then please test your work before upgrading.

Reporting Issues
----------------

[](#reporting-issues)

Please [create an issue](http://github.com/silverstripe/silverstripe-environmentcheck/issues) for any bugs you've found, or features you're missing.

###  Health Score

63

—

FairBetter than 99% of packages

Maintenance60

Regular maintenance activity

Popularity49

Moderate usage in the ecosystem

Community41

Growing community involvement

Maturity92

Battle-tested with a long release history

 Bus Factor3

3 contributors hold 50%+ of commits

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~77 days

Recently: every ~0 days

Total

60

Last Release

284d ago

Major Versions

2.6.x-dev → 3.0.0-beta12023-01-25

2.7.0-rc1 → 3.0.0-rc12023-03-30

2.x-dev → 3.0.12023-05-19

3.1.0-rc1 → 4.0.0-beta12025-03-26

3.x-dev → 4.0.02025-05-01

PHP version history (4 changes)2.4.0PHP ^7.3 || ^8.0

2.5.0PHP ^7.4 || ^8.0

3.0.0-beta1PHP ^8.1

4.0.0-beta1PHP ^8.3

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/654636?v=4)[Aaron Carlino](/maintainers/unclecheese)[@unclecheese](https://github.com/unclecheese)

![](https://www.gravatar.com/avatar/b0cba8b534e20e6ab4fff555a97b237a18436ebca1446fc0b29c8a8b504038b9?d=identicon)[GuySartorelli](/maintainers/GuySartorelli)

![](https://avatars.githubusercontent.com/u/111025?v=4)[Ingo Schommer](/maintainers/chillu)[@chillu](https://github.com/chillu)

![](https://www.gravatar.com/avatar/a25bc04c5720a36869d5a39c6449dde7eb43e19b7c8e666d5f632d6a9ab440b1?d=identicon)[emteknetnz](/maintainers/emteknetnz)

![](https://www.gravatar.com/avatar/afbb3dcc9ef29c1a6eedd6addcae5fce9ab1271915a85a4c349301b71237368d?d=identicon)[silverstripe-machine01](/maintainers/silverstripe-machine01)

![](https://www.gravatar.com/avatar/be6648e60fbab6f70bfc34dd8c14259562d28a47510a934ea9c01fe98633f3c2?d=identicon)[sminnee](/maintainers/sminnee)

![](https://avatars.githubusercontent.com/u/1168676?v=4)[Maxime Rainville](/maintainers/maxime-rainville)[@maxime-rainville](https://github.com/maxime-rainville)

---

Top Contributors

[![emteknetnz](https://avatars.githubusercontent.com/u/4809037?v=4)](https://github.com/emteknetnz "emteknetnz (45 commits)")[![GuySartorelli](https://avatars.githubusercontent.com/u/36352093?v=4)](https://github.com/GuySartorelli "GuySartorelli (45 commits)")[![robbieaverill](https://avatars.githubusercontent.com/u/5170590?v=4)](https://github.com/robbieaverill "robbieaverill (23 commits)")[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (17 commits)")[![frankmullenger](https://avatars.githubusercontent.com/u/50590?v=4)](https://github.com/frankmullenger "frankmullenger (14 commits)")[![dhensby](https://avatars.githubusercontent.com/u/563596?v=4)](https://github.com/dhensby "dhensby (13 commits)")[![chillu](https://avatars.githubusercontent.com/u/111025?v=4)](https://github.com/chillu "chillu (13 commits)")[![NightJar](https://avatars.githubusercontent.com/u/778003?v=4)](https://github.com/NightJar "NightJar (6 commits)")[![wilr](https://avatars.githubusercontent.com/u/101629?v=4)](https://github.com/wilr "wilr (5 commits)")[![andrewandante](https://avatars.githubusercontent.com/u/9702648?v=4)](https://github.com/andrewandante "andrewandante (4 commits)")[![ScopeyNZ](https://avatars.githubusercontent.com/u/3260989?v=4)](https://github.com/ScopeyNZ "ScopeyNZ (4 commits)")[![tractorcow](https://avatars.githubusercontent.com/u/936064?v=4)](https://github.com/tractorcow "tractorcow (4 commits)")[![mateusz](https://avatars.githubusercontent.com/u/118653?v=4)](https://github.com/mateusz "mateusz (3 commits)")[![sabina-talipova](https://avatars.githubusercontent.com/u/87288324?v=4)](https://github.com/sabina-talipova "sabina-talipova (3 commits)")[![scott1702](https://avatars.githubusercontent.com/u/10215604?v=4)](https://github.com/scott1702 "scott1702 (2 commits)")[![dnsl48](https://avatars.githubusercontent.com/u/9313746?v=4)](https://github.com/dnsl48 "dnsl48 (2 commits)")[![halkyon](https://avatars.githubusercontent.com/u/138450?v=4)](https://github.com/halkyon "halkyon (2 commits)")[![patbolo](https://avatars.githubusercontent.com/u/420098?v=4)](https://github.com/patbolo "patbolo (2 commits)")[![anotheredward](https://avatars.githubusercontent.com/u/228527?v=4)](https://github.com/anotheredward "anotheredward (1 commits)")[![assertchris](https://avatars.githubusercontent.com/u/200609?v=4)](https://github.com/assertchris "assertchris (1 commits)")

---

Tags

hacktoberfestchecksilverstripeenvironment

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/silverstripe-environmentcheck/health.svg)

```
[![Health](https://phpackages.com/badges/silverstripe-environmentcheck/health.svg)](https://phpackages.com/packages/silverstripe-environmentcheck)
```

###  Alternatives

[silverstripe/userforms

UserForms enables CMS users to create dynamic forms via a drag and drop interface and without getting involved in any PHP code

1321.0M72](/packages/silverstripe-userforms)[undefinedoffset/sortablegridfield

Adds drag and drop functionality to Silverstripe's GridField

941.2M50](/packages/undefinedoffset-sortablegridfield)[silverstripe/tagfield

Tag field for SilverStripe

571.2M45](/packages/silverstripe-tagfield)[silverstripe/subsites

Run multiple sites from a single SilverStripe install.

65392.9k20](/packages/silverstripe-subsites)[symbiote/silverstripe-advancedworkflow

Adds configurable workflow support to the CMS, with a GUI for creating custom workflow definitions.

46295.2k7](/packages/symbiote-silverstripe-advancedworkflow)[symbiote/silverstripe-addressable

SilverStripe addressable and geocoding module

2985.1k7](/packages/symbiote-silverstripe-addressable)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
