Download the PHP package shrikeh/guzzle-middleware-response-timer without Composer
On this page you can find all versions of the php package shrikeh/guzzle-middleware-response-timer. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download shrikeh/guzzle-middleware-response-timer
More information about shrikeh/guzzle-middleware-response-timer
Files in shrikeh/guzzle-middleware-response-timer
Package guzzle-middleware-response-timer
Short Description Measure response times in milliseconds over synchronous or asynchronous connections
License MIT
Informations about the package guzzle-middleware-response-timer
Response timer for Guzzle
A simple timer and logger that records response times for requests made by a Guzzle client to a PSR-3 log. Created initially to help Gousto get an idea of how microservices were interacting and performing.
It has some advantages over some other timers that already existed, in that it natively supports asynchronous calls, and uses the Request
object itself as the key, therefore allowing multiple calls to the same URI to be recorded separately.
Installation
Installation is recommended via composer:
Requirements and versioning
If installed by composer, all requirements should be taken care of. Semantic versioning is in use and strongly adhered to in tags 1.0 and beyond; branches before that are a little bit more free as I was shopping with ideas and the interface.
Tags <2.0 are 5.6 compatible; versions 2.0 and beyond are PHP 7.1+ only.
Basic usage
The following is a simple example using the quickStart()
method, which accepts a Psr\Log\LoggerInterface
logger (in this case, a simple file stream implemented by Monolog):
Exception handling
By default, the Middleware::quickStart()
method boots the start
and stop
handlers with a TriggerErrorHandler
that simply swallows any exception thrown and generates an E_USER_NOTICE
error instead.
This is to ensure that any problems with logging do not cause any application-level problems: there isn't a default scenario in which a problem logging response times should break your application. Nor, as the exception is most likely to do with the underlying Logger
, is there logging of the exception thrown.
If you wish to throw exceptions and handle them differently, load your handlers with an implementation of the ExceptionHandlerInterface
.
Service Provider
The package comes with a ServiceProvider for Pimple, my preferred choice of standalone PSR-11 compliant container. Pimple itself is not listed as a dependency in require
(although it is in require-dev
for testing), so you will need to add it to your project directly if you wish to use the service provider:
As the service provider relies on a PSR-3 Logger, building a Container requires passing this in: