How to run Laminas Diagnostics in Symfony

Vasil Dakov
3 min readFeb 9, 2024

Introduction

Laminas Diagnostics is a handy standalone component that provides diagnostic tests for real-world PHP applications. It ships with lots of diagnostic checks and you can check if a given unix process is running, the required PHP extensions are installed, configurations exist etc. In this post, I am going to share how the Diagnostics component can be used together with the Symfony framework.

<?php
# diagnostics.php

use Laminas\Diagnostics\Check;
use Laminas\Diagnostics\Runner\Runner;
use Laminas\Diagnostics\Runner\Reporter\BasicConsole;

include 'vendor/autoload.php';

// Create Runner instance
$runner = new Runner();

// Add checks
$runner->addCheck(new Check\DirWritable('/tmp'));
$runner->addCheck(new Check\DiskFree(100000000, '/tmp'));

// Add console reporter
$runner->addReporter(new BasicConsole(80, true));

// Run all checks
$results = $runner->run();

// Emit an appropriate exit code
$status = ($results->getFailureCount() + $results->getWarningCount()) > 0 ? 1 : 0;
exit($status);

Installation

I presume you already have set up your Symfony project, so you can use PHP composer to install the diagnostics components:

composer require laminas/laminas-diagnostics

Usage

--

--