Download the PHP package rmzamora/zenddiagnostics without Composer
On this page you can find all versions of the php package rmzamora/zenddiagnostics. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download rmzamora/zenddiagnostics
More information about rmzamora/zenddiagnostics
Files in rmzamora/zenddiagnostics
Package zenddiagnostics
Short Description A set of components for performing diagnostic tests in PHP applications
License BSD-3-Clause
Homepage https://github.com/zendframework/ZendDiagnostics
Informations about the package zenddiagnostics
ZendDiagnostics
Simple component for performing diagnostic tests in real-world PHP applications.
It currently ships with the following Diagnostic Checks:
- ApcFragmentation - check if APC memory fragmentation is below given threshold,
- ApcMemory - check available APC memory,
- Callback - call a user-defined diagnostic function,
- ClassExists - make sure class exists in current environment,
- CouchDBCheck - check if connection is possible,
- CpuPerformance - check server CPU performance is above baseline,
- DirReadable - make sure given path is readable,
- DirWritable - make sure given path is writable,
- DiskFree - check there's enough free space on given path,
- DiskUsage - check if the disk usage is below warning/critical percent thresholds,
- DoctrineMigration - make sure all migrations are applied.
- ExtensionLoaded - make sure extension is loaded,
- GuzzleHttpService - check if given http host is responding using Guzzle,
- HttpService - check if given http host is responding,
- Memcache - check if memcache extension is loaded and given server is reachable,
- OpCacheMemory - check if the OpCache memory usage is below warning/critical thresholds,
- PDOCheck - check if connection is possible,
- PhpVersion - make sure that PHP version matches constraint,
- PhpFlag - make sure that given PHP flag (feature) is turned on or off.
- ProcessRunning - check if a process with given name or ID is currently running,
- RabbitMQ - Validate that a RabbitMQ service is running,
- Redis - Validate that a Redis service is running,
- SecurityAdvisory - check installed composer dependencies against SensioLabs SA database,
- StreamWrapperExists - make sure given stream wrapper is available.
File validation checks:
- IniFile - check if given INI file is available and valid,
- JsonFile - check if given JSON file is available and valid,
- XmlFile - check if given XML file is available and valid,
- YamlFile - check if given YAML file is available and valid
Using diagnostics with Zend Framework 2
- Install the ZFTool module.
- Enable diagnostic tests in your application config.php.
- In your console type
php public/index.php diag
to run diagnostics.
Using diagnostics with Symfony 2
- Install the LiipMonitorBundle.
- Enable diagnostic tests in your application configuration.
- In your console type
./app/console monitor:health
to run diagnostics.
Using diagnostics with PSR-7 middleware
Install the rstgroup/diagnostics-middleware.
Using diagnostics in plain PHP
- Add ZendDiagnostics component to your application
- via composer - run
composer require zendframework/zenddiagnostics:dev-master
- via git - clone https://github.com/zendframework/ZendDiagnostics.git
- manually - download and extract zip package
- via composer - run
- If you are not using Composer, use
include "autoload_register.php";
- Create an instance of
ZendDiagnostics\Runner
- Add tests using
Runner::addTest()
- Optionally add a reporter to display progress using
Runner::addReporter()
- Run diagnostics
Runner::run()
For example:
``
You can now run the file in your console (command line):
`
Using Result Collection
The Runner will always return a Result\Collection (even without any attached Reporter). This collection contains results for all tests and failure counters.
Simple example:
``
Architecture
A single diagnostic Check performs one particular test on the application or environment.
It must return a Result which implements one of the following result interfaces:
- Success - in case the check ran through without any issue.
- Warning - in case there might be something wrong.
- Failure - when the test failed and an intervention is required.
Each test Result can additionally return:
- result message via
getMessage()
. It can be used to describe the context of the result. - result data via
getData()
. This can be used for providing detailed information on the cause of particular result, which might be useful for debugging problems.
One can define additional result interfaces, i.e. denoting severity levels (i.e. critical, alert, notice) or appropriate actions (i.e. missing, incomplete). However, it is recommended to extend the primary set of Success, Warning, Failure interfaces for compatibility with other applications and libraries.
Writing custom Checks
A Check class has to implement Check and provide the following methods:
``
The main check()
method is responsible for doing the actual check and is expected to return a
Result. It is recommended to use the built-in result classes for
compatibility with Runner and other checks.
Here is an example trivial class, that will check if PHP default timezone is set to UTC.
``
Writing custom Reporters
A Reporter is a class implementing ReporterInterface.
``
A Runner invokes above methods while running diagnostics in the following order:
onStart
- right after callingRunner::run()
onBeforeRun
- before each individual Check.onAfterRun
- after each individual check has finished running.onFinish
- after Runner has finished its job.onStop
- in case Runner has been interrupted:- when the Reporter has returned
false
fromonAfterRun
method - or when runner is configured with
setBreakOnFailure(true)
and one of the Checks fails.
- when the Reporter has returned
Some Reporter methods can be used to interrupt the operation of a Runner:
onBeforeRun(Check $check)
- in case this method returnsfalse
, that particular Check will be omitted.onAfterRun(Check $check, Result($result))
- in case this method returnsfalse
, the Runner will abort checking.
All other return values are ignored.
ZendDiagnostics ships with a simple Console reporter - it can serve as a good example on how to write your own Reporters.
Built-in diagnostics checks
ZendDiagnostics provides several "just add water" checks you can use straight away.
The following built-in tests are currently available:
ApcFragmentation
Make sure that APC memory fragmentation level is below given threshold:
``
ApcMemory
Check APC memory usage percent and make sure it's below given threshold.
``
Callback
Run a function (callback) and use return value as the result:
``
Note: 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.
ClassExists
Check if a class (or an array of classes) exist. For example:
``
CpuPerformance
Benchmark CPU performance and return failure if it is below the given ratio. The baseline for performance calculation
is the speed of 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:
``
DirReadable
Check if a given path (or array of paths) points to a directory and it is readable.
``
DirWritable
Check if a given path (or array of paths) points to a directory and if it can be written to.
``
DiskFree
Check if there is enough remaining free disk space.
The first parameter is the minimum disk space, which can be supplied as integer (in bytes, i.e. 1024
)
or as a string with a multiplier (IEC, SI or Jedec, i.e. "150MB"
). The second parameter is the path to check -
on *NIX systems it is an ordinary path (i.e. /home
), on Windows systems it is a drive letter (i.e. "C:"
).
``
ExtensionLoaded
Check if a PHP extension (or an array of extensions) is currently loaded.
``
HttpService
Attempt connection to given HTTP host or IP address and try to load a web page. The check also supports checking response codes and page contents.
``
GuzzleHttpService
Attempt connection to 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.
``
Memcache
Attempt to connect to given Memcache server.
``
PhpVersion
Check if current PHP version matches the given requirement. The test accepts 2 parameters - baseline version and optional comparison operator.
``
PhpFlag
Make sure that given PHP flag(s) is enabled or disabled (i.e. as defined in php.ini). You can use this test to alert the user about unsafe or behavior-changing PHP settings.
``
ProcessRunning
Check if a given unix process is running. This check supports PIDs and process names.
``
RabbitMQ
Validate that a RabbitMQ service is running.
Redis
Validate that a Redis service is running.
SecurityAdvisory
Run a security check of libraries locally installed by Composer against SensioLabs Security Advisory database and warn about potential security vulnerabilities.
``
StreamWrapperExists
Check if a given stream wrapper (or an array of wrappers) is available. For example:
``
DoctrineMigration
Make sure all migrations are applied:
``
IniFile
Read an INI-file from the given path and try to parse it.
``
JsonFile
Read a JSON-file from the given path and try to decode it.
``
XmlFile
Read an XML-file from the given path, try to parse it and validate it agaist its DTD schema if possible.
``
YamlFile
Read a YAML-file from the given path and try to parse it.
``