Download the PHP package ctw/ctw-middleware-responsetime without Composer
On this page you can find all versions of the php package ctw/ctw-middleware-responsetime. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download ctw/ctw-middleware-responsetime
More information about ctw/ctw-middleware-responsetime
Files in ctw/ctw-middleware-responsetime
Package ctw-middleware-responsetime
Short Description This PSR-15 middleware adds an X-Response-Time in milliseconds to the Response header.
License BSD-3-Clause
Informations about the package ctw-middleware-responsetime
Package "ctw/ctw-middleware-responsetime"
PSR-15 middleware that adds an X-Response-Time header showing request processing duration in milliseconds.
Introduction
Why This Library Exists
Understanding how long your application takes to process requests is essential for performance monitoring and optimization. While external tools can measure total response time, they include network latency. Measuring at the application level provides the true processing time.
This middleware adds an X-Response-Time header to every response showing:
- Processing duration: Time from request arrival to response generation
- Millisecond precision: Three decimal places for accurate measurement
- Consistent format: Standardized header for easy parsing by monitoring tools
- Zero overhead: Uses PHP's native
microtime()for minimal performance impact
Problems This Library Solves
- Invisible performance: Without timing data, slow requests go unnoticed
- External tool inaccuracy: Network-based measurements include latency, not just processing time
- Manual instrumentation: Adding timing code to every handler is tedious and error-prone
- Inconsistent measurement: Different timing implementations across the application
- Missing production visibility: Development profilers aren't available in production
Where to Use This Library
- Performance monitoring: Track response times across your application
- SLA verification: Ensure responses meet required time thresholds
- Debugging slowness: Quickly identify slow requests from response headers
- Load testing: Analyze response time distribution under load
- Client-side monitoring: JavaScript can read the header for real-user monitoring
- Log correlation: Include response time in access logs for analysis
Design Goals
- High precision: Milliseconds with three decimal places (microsecond resolution)
- Accurate timing: Uses
REQUEST_TIME_FLOATas start time for precision - Standard format:
X.XXX msformat is human-readable and parseable - Minimal overhead: Simple subtraction and header addition
- Universal application: Works for HTML, JSON, and all response types
Requirements
- PHP 8.3 or higher
- ctw/ctw-middleware ^4.0
Installation
Install by adding the package as a Composer requirement:
Usage Examples
Basic Pipeline Registration (Mezzio)
ConfigProvider Registration
Response Header Output
Inspecting with cURL
Inspecting in Browser DevTools
- Open Developer Tools (F12)
- Navigate to the Network tab
- Select a request
- View Response Headers
- Look for
X-Response-Time
Header Format
| Component | Description |
|---|---|
| Value | Processing time in milliseconds |
| Precision | Three decimal places (microsecond resolution) |
| Format | X.XXX ms |
| Example | 45.123 ms |
Timing Calculation
The middleware calculates response time as:
Where:
start_time=$_SERVER['REQUEST_TIME_FLOAT'](request arrival)end_time=microtime(true)(response generation complete)
Use Cases
Log Analysis
Performance Alerting
Load Testing
All versions of ctw-middleware-responsetime with dependencies
ctw/ctw-middleware Version ^5.0
psr/container Version ^1.0 || ^2.0
psr/http-message Version ^1.1 || ^2.0
psr/http-server-handler Version ^1.0