Skip to content

TimingMiddleware

Records timing spans for downstream middleware execution.

class TimingMiddleware implements MiddlewareInterface

ImplementsMiddlewareInterface
SourceMiddleware/TimingMiddleware.php

public function __construct(bool $emitHeader = false, ClockInterface $clock = new SystemClock(…)): mixed

ParameterTypeDescription
$emitHeaderbool
$clockClockInterface

Returns mixed

MethodDescription
process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterfaceMeasures total pipeline time into the request’s ExecutionState metrics.

public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface

Measures total pipeline time into the request’s ExecutionState metrics.

Runs at the head of the bootstrap phase so the measurement spans essentially the whole stack. Reuses the ExecutionState already on the request, or creates one and attaches it, then writes total_ms into its metrics after the downstream handler returns. The X-Quiote-Timing header is added only when the constructor enabled it, and is skipped without complaint if the metrics cannot be JSON-encoded.

ParameterTypeDescription
$requestServerRequestInterface
$handlerRequestHandlerInterface

Returns ResponseInterface