PHPackages                             ctw/ctw-middleware-generatedat - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [HTTP &amp; Networking](/categories/http)
4. /
5. ctw/ctw-middleware-generatedat

ActiveLibrary[HTTP &amp; Networking](/categories/http)

ctw/ctw-middleware-generatedat
==============================

This PSR-15 middleware adds an X-Generated-At timestamp to the Response header.

4.0.4(5mo ago)119BSD-3-ClausePHPPHP ^8.3CI passing

Since Mar 13Pushed 5mo ago1 watchersCompare

[ Source](https://github.com/jonathanmaron/ctw-middleware-generatedat)[ Packagist](https://packagist.org/packages/ctw/ctw-middleware-generatedat)[ RSS](/packages/ctw-ctw-middleware-generatedat/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (5)Versions (32)Used By (0)

Package "ctw/ctw-middleware-generatedat"
========================================

[](#package-ctwctw-middleware-generatedat)

[![Latest Stable Version](https://camo.githubusercontent.com/3bb5d73709cb45c949b309d7c4f2b6f9138e8d8b859ce0d3fd459717c61e2eaa/68747470733a2f2f706f7365722e707567782e6f72672f6374772f6374772d6d6964646c65776172652d67656e65726174656461742f762f737461626c65)](https://packagist.org/packages/ctw/ctw-middleware-generatedat)[![GitHub Actions](https://github.com/jonathanmaron/ctw-middleware-generatedat/actions/workflows/tests.yml/badge.svg)](https://github.com/jonathanmaron/ctw-middleware-generatedat/actions/workflows/tests.yml)[![Scrutinizer Build](https://camo.githubusercontent.com/02352d9236e7b542f765487c434f6d8970ce80f9593374fcdd22880d62bd506f/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6a6f6e617468616e6d61726f6e2f6374772d6d6964646c65776172652d67656e65726174656461742f6261646765732f6275696c642e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/jonathanmaron/ctw-middleware-generatedat/build-status/master)[![Scrutinizer Quality](https://camo.githubusercontent.com/4f52376d8b5ec03408040b058454cd81a34189ed8068d3e75f600ebcbf228882/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6a6f6e617468616e6d61726f6e2f6374772d6d6964646c65776172652d67656e65726174656461742f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/jonathanmaron/ctw-middleware-generatedat/?branch=master)[![Code Coverage](https://camo.githubusercontent.com/cdd9a98f32fcffa5996395386a265508934c7e1ebe7ce04b312fd28351fd9ad9/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6a6f6e617468616e6d61726f6e2f6374772d6d6964646c65776172652d67656e65726174656461742f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/jonathanmaron/ctw-middleware-generatedat/?branch=master)

PSR-15 middleware that adds an `X-Generated-At` header with an ISO 8601 UTC timestamp to every response.

Introduction
------------

[](#introduction)

### Why This Library Exists

[](#why-this-library-exists)

Knowing when a response was generated is valuable for debugging, monitoring, and cache validation. While HTTP provides standard caching headers like `Date` and `Last-Modified`, these are often set by web servers or proxies rather than the application itself.

The `X-Generated-At` header provides an application-level timestamp indicating exactly when your PHP code generated the response:

- **Debugging**: Quickly identify if you're seeing a cached response or a freshly generated one
- **Performance monitoring**: Compare generation timestamps with response receipt times
- **Cache verification**: Confirm that CDN or browser caches are serving expected content
- **Audit trails**: Log when specific responses were generated for compliance purposes

### Problems This Library Solves

[](#problems-this-library-solves)

1. **Cache ambiguity**: Difficult to determine if a response came from cache or was freshly generated
2. **Timezone confusion**: Server timestamps may use local time; this middleware uses consistent UTC format
3. **Missing application timestamps**: Web server `Date` headers don't reflect when application code executed
4. **Debugging complexity**: Without timestamps, correlating logs with responses requires additional tooling
5. **Inconsistent formatting**: Custom timestamp implementations vary; this provides ISO 8601 standard format

### Where to Use This Library

[](#where-to-use-this-library)

- **Development environments**: Verify that code changes are being reflected in responses
- **Production applications**: Monitor response freshness and debug caching issues
- **API services**: Provide clients with precise response generation timestamps
- **Multi-tier architectures**: Distinguish between application, CDN, and proxy caching
- **Debugging sessions**: Correlate browser responses with server-side logs

### Design Goals

[](#design-goals)

1. **ISO 8601 format**: Uses standard `Y-m-d\TH:i:s\Z` format for universal parsing
2. **UTC timezone**: Eliminates timezone ambiguity with consistent UTC timestamps
3. **Request-based accuracy**: Uses `REQUEST_TIME_FLOAT` for precise timing
4. **Minimal overhead**: Simple header addition with negligible performance impact
5. **Non-intrusive**: Adds metadata without modifying response content

Requirements
------------

[](#requirements)

- PHP 8.3 or higher
- ctw/ctw-middleware ^4.0

Installation
------------

[](#installation)

Install by adding the package as a [Composer](https://getcomposer.org) requirement:

```
composer require ctw/ctw-middleware-generatedat
```

Usage Examples
--------------

[](#usage-examples)

### Basic Pipeline Registration (Mezzio)

[](#basic-pipeline-registration-mezzio)

```
use Ctw\Middleware\GeneratedAtMiddleware\GeneratedAtMiddleware;

// In config/pipeline.php or similar
$app->pipe(GeneratedAtMiddleware::class);
```

### Response Header Output

[](#response-header-output)

```
HTTP/1.1 200 OK
Content-Type: text/html; charset=UTF-8
X-Generated-At: 2024-01-15T14:30:45Z
```

### Inspecting with cURL

[](#inspecting-with-curl)

```
curl -I https://example.com/

# Response includes:
# X-Generated-At: 2024-01-15T14:30:45Z
```

### Inspecting in Browser DevTools

[](#inspecting-in-browser-devtools)

1. Open Developer Tools (F12)
2. Navigate to the Network tab
3. Select a request
4. View Response Headers
5. Look for `X-Generated-At`

### ConfigProvider Registration

[](#configprovider-registration)

The package includes a `ConfigProvider` for automatic factory registration:

```
// config/config.php
return [
    // ...
    \Ctw\Middleware\GeneratedAtMiddleware\ConfigProvider::class,
];
```

### Header Format

[](#header-format)

ComponentValueDescriptionHeader name`X-Generated-At`Custom header indicating generation timeFormatISO 8601`Y-m-d\TH:i:s\Z`TimezoneUTCIndicated by `Z` suffixExample`2024-01-15T14:30:45Z`January 15, 2024 at 14:30:45 UTC

###  Health Score

45

—

FairBetter than 92% of packages

Maintenance70

Regular maintenance activity

Popularity8

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity79

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~57 days

Recently: every ~131 days

Total

31

Last Release

168d ago

Major Versions

1.0.1 → 2.0.02022-02-14

2.0.0 → 3.0.02022-07-07

3.0.22 → 4.0.02024-06-18

PHP version history (4 changes)1.0.0PHP ^7.4 || ^8.0

3.0.0PHP ^8.0

3.0.9PHP ^8.1

4.0.0PHP ^8.3

### Community

Maintainers

![](https://www.gravatar.com/avatar/18d8bc9bdee8ab1b0cfccce6a06d2438acbed3a58b0046c4834c5678f6769342?d=identicon)[jonathanmaron](/maintainers/jonathanmaron)

---

Top Contributors

[![jonathanmaron](https://avatars.githubusercontent.com/u/298462?v=4)](https://github.com/jonathanmaron "jonathanmaron (56 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/ctw-ctw-middleware-generatedat/health.svg)

```
[![Health](https://phpackages.com/badges/ctw-ctw-middleware-generatedat/health.svg)](https://phpackages.com/packages/ctw-ctw-middleware-generatedat)
```

###  Alternatives

[nelmio/api-doc-bundle

Generates documentation for your REST API from attributes

2.3k63.6M233](/packages/nelmio-api-doc-bundle)[api-platform/core

Build a fully-featured hypermedia or GraphQL API in minutes!

2.6k48.1M236](/packages/api-platform-core)[api-platform/state

API Platform state interfaces

223.4M57](/packages/api-platform-state)[akrabat/ip-address-middleware

PSR-15 middleware that determines the client IP address and stores it as a ServerRequest attribute

1702.5M18](/packages/akrabat-ip-address-middleware)[mezzio/mezzio-authentication-oauth2

OAuth2 (server) authentication middleware for Mezzio and PSR-7 applications.

28483.0k2](/packages/mezzio-mezzio-authentication-oauth2)[mezzio/mezzio-authentication

Authentication middleware for Mezzio and PSR-7 applications

121.6M26](/packages/mezzio-mezzio-authentication)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
