Diagnostic Checks

zendframework/zenddiagnostics provides several "just add water" checks you can use straight away.

The following built-in tests are currently available:


Make sure that APC memory fragmentation level is below a given threshold:

use ZendDiagnostics\Check\ApcFragmentation;

// Display a warning with fragmentation > 50% and failure when above 90%
$fragmentation = new ApcFragmentation(50, 90);


Check APC memory usage percent and make sure it's below a given threshold.

use ZendDiagnostics\Check\ApcMemory;

// Display a warning with memory usage is above 70% and a failure above 90%
$checkFreeMemory = new ApcMemory(70, 90);


Run a function (callback) and use its return value as the result:

use ZendDiagnostics\Check\Callback;
use ZendDiagnostics\Result\Success;
use ZendDiagnostics\Result\Failure;

$checkDbFile = new Callback(function() {
    $path = __DIR__ . '/data/db.sqlite';
    if (is_file($path) && is_readable($path) && filesize($path)) {
        return new Success('Db file is ok');

        return new Failure('There is something wrong with the db file');

Callback signature

The callback must return either a boolean (true for success, false for failure), or a valid instance of ResultInterface. All other objects will result in an exception, and scalars (i.e. a string) will be interpreted as warnings.


Check if a class (or an array of classes) exists. For example:

use ZendDiagnostics\Check\ClassExists;

$checkLuaClass = new ClassExists('Lua');
$checkRbacClasses = new ClassExists([


Benchmark CPU performance and return failure if it is below the given ratio. The baseline for performance calculation is the speed of an Amazon EC2 Micro Instance (Q1 2013). You can specify the expected performance for the test, where a ratio of 1.0 (one) means at least the speed of EC2 Micro Instance. A ratio of 2 would mean "at least double the performance of EC2 Micro Instance" and a fraction of 0.5 means "at least half the performance of Micro Instance".

The following check will test if current server has at least half the CPU power of EC2 Micro Instance:

use ZendDiagnostics\Check\CpuPerformance;

$checkMinCPUSpeed = new CpuPerformance(0.5); // at least 50% of EC2 micro instance


Check if a given path (or array of paths) points to a directory and it is readable.

use ZendDiagnostics\Check\DirReadable;

$checkPublic = new DirReadable('public/');
$checkAssets = new DirReadable([
    __DIR__ . '/assets/img',
    __DIR__ . '/assets/js',


Check if a given path (or array of paths) points to a directory and if it can be written to.

use ZendDiagnostics\Check\DirWritable;

$checkTemporary = new DirWritable('/tmp');
$checkAssets    = new DirWritable([
    __DIR__ . '/assets/customImages',
    __DIR__ . '/assets/customJs',
    __DIR__ . '/assets/uploads',


Check if there is enough remaining free disk space.

The first parameter is the minimum disk space, which can be supplied as an integer (in bytes, e.g. 1024) or as a string with a multiplier (IEC, SI or Jedec; e.g. "150MB"). The second parameter is the path to check; on *NIX systems it is an ordinary path (e.g. /home), while on Windows systems it is a drive letter (e.g. "C:").

use ZendDiagnostics\Check\DiskFree;

$tempHasAtLeast100Megs  = new DiskFree('100MB', '/tmp');
$homeHasAtLeast1TB      = new DiskFree('1TiB',  '/home');
$dataHasAtLeast900Bytes = new DiskFree(900, __DIR__ . '/data/');


Check if a PHP extension (or an array of extensions) is currently loaded.

use ZendDiagnostics\Check\ExtensionLoaded;

$checkMbstring    = new ExtensionLoaded('mbstring');
$checkCompression = new ExtensionLoaded([


Attempt connection to a given HTTP host or IP address and try to load a web page. The check also supports checking response codes and page contents.

use ZendDiagnostics\Check\HttpService;

// Try to connect to google.com
$checkGoogle = new HttpService('www.google.com');

// Check port 8080 on localhost
$checkLocal = new HttpService('', 8080);

// Check that the page exists (response code must equal 200)
$checkPage = new HttpService('www.example.com', 80, '/some/page.html', 200);

// Check page content
$checkPageContent = new HttpService(
    '<title>Hello World</title>'


Attempt connection to a given HTTP host or IP address and try to load a web page using Guzzle. The check also supports checking response codes and page contents.

The constructor signature of the GuzzleHttpService is as follows:

 * @param string|Psr\Http\Message\RequestInterface|GuzzleHttp\Message\RequestInterface $requestOrUrl
 *     The absolute url to check, or a fully-formed request instance.
 * @param array $headers An array of headers used to create the request
 * @param array $options An array of guzzle options to use when sending the request
 * @param int $statusCode The response status code to check
 * @param null $content The response content to check
 * @param null|GuzzleHttp\ClientInterface $guzzle Instance of guzzle to use
 * @param string $method The method of the request
 * @param mixed $body The body of the request (used for POST, PUT and DELETE requests)
 * @throws InvalidArgumentException
public function __construct(
    array $headers = [],
    array $options = [],
    $statusCode = 200,
    $content = null,
    $guzzle = null,
    $method = 'GET',
    $body = null


use ZendDiagnostics\Check\GuzzleHttpService;

// Try to connect to google.com
$checkGoogle = new GuzzleHttpService('www.google.com');

// Check port 8080 on localhost
$checkLocal = new GuzzleHttpService('');

// Check that the page exists (response code must equal 200)
$checkPage = new GuzzleHttpService('www.example.com/some/page.html');

// Check page content
$checkPageContent = new GuzzleHttpService(
    '<title>Hello World</title>'

// Check that the post request returns the content
$checkPageContent = new GuzzleHttpService(
    ['post_field' => 'post_value']

You can send JSON data by either providing a Content-Type header that includes a JSON content type, or creating a request instance with JSON content:

// Send page content
$checkPageContent = new GuzzleHttpService(
    ['Content-Type' => 'application/json'],
    ['ping' => microtime()]

// Assuming Guzzle 6:
use GuzzleHttp\Psr7\Request;
$request = new Request(
    ['Content-Type' => 'application/json'],
    json_encode(['ping' => microtime()])
$checkPageContent = new GuzzleHttpService($request);


Attempt to connect to given Memcache server.

use ZendDiagnostics\Check\Memcache;

$checkLocal  = new Memcache(''); // default port
$checkBackup = new Memcache('', 11212);


Attempt to connect to the given Memcached server.

use ZendDiagnostics\Check\Memcached;

$checkLocal  = new Memcached(''); // default port
$checkBackup = new Memcached('', 11212);


Check if connection to MongoDb is possible

use ZendDiagnostics\Check\Mongo;

$mongoCheck = new Mongo('mongodb://');
// and with user/password
$mongoCheck = new Mongo('mongodb://user:password@');


Check if a connection to a given MongoDb server is possible.

use ZendDiagnostics\Check\Mongo;

$mongoCheck = new Mongo('mongodb://');
// and with user/password
$mongoCheck = new Mongo('mongodb://user:password@');


Check if the current PHP version matches the given requirement. The test accepts 2 parameters: baseline version and optional comparison operator.

use ZendDiagnostics\Check\PhpVersion;

$require545orNewer  = new PhpVersion('5.4.5');
$rejectBetaVersions = new PhpVersion('5.5.0', '<');


Make sure that the provided PHP flag(s) is enabled or disabled (as defined in php.ini). You can use this test to alert the user about unsafe or behavior-changing PHP settings.

use ZendDiagnostics\Check\PhpFlag;

// This check will fail if use_only_cookies is not enabled
$sessionOnlyUsesCookies = new PhpFlag('session.use_only_cookies', true);

// This check will fail if safe_mode has been enabled
$noSafeMode = new PhpFlag('safe_mode', false);

// The following will fail if any of the flags is enabled
$check = new PhpFlag([
], false);


Check if a given unix process is running. This check supports PIDs and process names.

use ZendDiagnostics\Check\ProcessRunning;

$checkApache = new ProcessRunning('httpd');
$checkProcess1000 = new ProcessRunning(1000);


Validate that a RabbitMQ service is running.

use ZendDiagnostics\Check\RabbitMQ;

$rabbitMQCheck = new RabbitMQ('localhost', 5672, 'guest', 'guest', '/');


Validate that a Redis service is running.

use ZendDiagnostics\Check\Redis;

$redisCheck = new Redis('localhost', 6379, 'secret');


Run a security check of libraries locally installed by Composer against SensioLabs Security Advisory database, and warn about potential security vulnerabilities.

use ZendDiagnostics\Check\SecurityAdvisory;

// Warn about any packages that might have security vulnerabilities
// and require updating
$security = new SecurityAdvisory();

// Check another composer.lock
$security = new SecurityAdvisory('/var/www/project/composer.lock');


Check if a given stream wrapper (or an array of wrappers) is available. For example:

use ZendDiagnostics\Check\StreamWrapperExists;

$checkOGGStream   = new StreamWrapperExists('ogg');
$checkCompression = new StreamWrapperExists([


Make sure all migrations are applied:

use Doctrine\DBAL\Migrations\Configuration\Configuration;
use Doctrine\ORM\EntityManager;
use ZendDiagnostics\Check\DoctrineMigration;

$em = EntityManager::create(/* config */);
$migrationConfig = new Configuration($em);
$check = new DoctrineMigration($migrationConfig);

Found a mistake or want to contribute to the documentation? Edit this page on GitHub!