PHPackages                             fideloper/conditionalrequest - 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. fideloper/conditionalrequest

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

fideloper/conditionalrequest
============================

Handle HTTP validation Caching using If-\* Headers on requests

1082[1 issues](https://github.com/fideloper/ConditionalRequest/issues)PHP

Since Jun 10Pushed 13y ago1 watchersCompare

[ Source](https://github.com/fideloper/ConditionalRequest)[ Packagist](https://packagist.org/packages/fideloper/conditionalrequest)[ RSS](/packages/fideloper-conditionalrequest/feed)WikiDiscussions master Synced yesterday

READMEChangelogDependenciesVersions (2)Used By (0)

Conditional Requests
====================

[](#conditional-requests)

**Note:** This library has some [HTTP validation caching](http://symfony.com/doc/2.0/book/http_cache.html#index-10) logic that Symfony includes. Specifically, Symfony can handle Conditional GET requests "out of the box." However, this library also includes support for Concurrency Control (for validating POST or PUT update requests).

The Situation
-------------

[](#the-situation)

Frameworks don't often give you tools to control HTTP caching mechanisms, such as setting ETags or Last-Modified dates.

Goals
-----

[](#goals)

This package aims to help you with conditional HTTP requests, using [validation caching](http://www.w3.org/Protocols/rfc2616/rfc2616-sec13.html#sec13.3) mechanisms

1. Allow Validation Caching (using `ETag`s with `If-Match`, `If-None-Match` as well as `Last-Modified` with `If-Modified-Since`, `If-Unmodified-Since` headers)
2. Help developers learn about HTTP and Caching, a topic which is often ignored

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

[](#installation)

[![Build Status](https://camo.githubusercontent.com/ebf6776cdd00ef8abd1a7eef5c390edb5064b983865aaaed2430affca336942f/68747470733a2f2f7472617669732d63692e6f72672f666964656c6f7065722f436f6e646974696f6e616c526571756573742e706e673f6272616e63683d6d6173746572)](https://travis-ci.org/fideloper/ConditionalRequest)

This is a Composer package, available on Packagist.

To install it, edit your composer.json file and add:

```
{
    "require": {
        "fideloper/conditionalrequest": "dev-master"
    }
}
```

The default install will include some Symfony and Laravel (Illuminate) libraries. However these don't necessarily need to be used.

To install:

```
$ composer install

```

To install with Phpunit and Mockery to hack on:

```
$ composer install --dev

```

Methods Available:
------------------

[](#methods-available)

1. **using** ( ResourceInterface *$resource* ) - Use ResourceInterface, which sets the ETag and/or Last Modified date automatically
2. **setEtag** ( string *$etag* ) - Set the ETag for an entity "manually"
3. **setLastModified**\* ( DateTime *$lastModified* ) - Set the last modified date for an entity "manually"
4. bool **doGet** () - Determine if your app should respond to a GET request with entity (the resource) or `304 Not Modified`
5. bool **doUpate** () - Determine if your app should update the entity/resource in a PUT/POST request or respond with `412 Precondition Failed`

Basic Usage:
------------

[](#basic-usage)

1. [Laravel/Symfony](https://github.com/fideloper/ConditionalRequest/wiki/Laravel-Symfony)
2. Zend \[Future\]
3. "Pure" PHP \[Future\]

More Usage:
-----------

[](#more-usage)

**For more complete usage examples and explanation, see the [Wiki](https://github.com/fideloper/ConditionalRequest/wiki).**

Some Explanation
----------------

[](#some-explanation)

There are a few types of caching:

1. In-app caching (Memcache, Redis, other memory stores)
2. HTTP caching - gateway, proxy and private (aka browsers, and similar)

Making a response (web page, api-response, etc) cachable by third-parties is part of the HTTP cache mechanisms. Which cache mechanisms you use depends on your use case.

The HTTP spec defines 2 methods of HTTP caching:

1. **Validation** - save bandwidth by not having an origin server reply with a full message body (header-only response)
2. **Expiration** - to save round-trips to the origin server - a cache can potentially serve a response directly, saving the origin server from even knowing about the request

### Validation caching

[](#validation-caching)

Validation Caching, done with if-\* headers (mainly if-match, if-none-match, if-modified-since, if-unmodified-since) is useful for 2 things:

#### Conditional GET requests

[](#conditional-get-requests)

A server can tell the request 'nothing has changed since you last checked'. The client then knows to use its last-known version of the resource (assuming the reuslt of prior requests). This is good for mobile APIs where the bandwidth of re-sending a message body can be saved via conditional requests.

A server can respond with the resource as normal, or return a `304 Not Modified` response if the resource wasn't updated since the client last asked for it.

#### Concurrency Control

[](#concurrency-control)

In a PUT (or possibly POST) request, a server can check if the resource being updated was changed since the requester last checked (solves the [Lost Update Problem](http://www.w3.org/1999/04/Editing/)). This is good for APIs with a lot of writes (updates) to resources.

A server can respond with `412 Precondition Failed` if the client requesting the update doesn't have the latest knowledge of the resource.

**This library is coded to help with Validation Cacheing.**

### Expiration caching

[](#expiration-caching)

Expiration caching, done with Expires, Cache-Control, Last-Modified and other headers, can aid in caching a response for the next user (or even for one specific user), saving your server(s) from some traffic load.

###  Health Score

22

—

LowBetter than 21% of packages

Maintenance18

Infrequent updates — may be unmaintained

Popularity12

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity43

Maturing project, gaining track record

 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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/5ffe7f19bdf080aaa14107239624d682f2e1b139b9459e93b56966649a4d7873?d=identicon)[fideloper](/maintainers/fideloper)

---

Top Contributors

[![fideloper](https://avatars.githubusercontent.com/u/467411?v=4)](https://github.com/fideloper "fideloper (18 commits)")

### Embed Badge

![Health badge](/badges/fideloper-conditionalrequest/health.svg)

```
[![Health](https://phpackages.com/badges/fideloper-conditionalrequest/health.svg)](https://phpackages.com/packages/fideloper-conditionalrequest)
```

###  Alternatives

[php-http/cache-plugin

PSR-6 Cache plugin for HTTPlug

25126.1M81](/packages/php-http-cache-plugin)[illuminate/http

The Illuminate Http package.

11937.9M6.7k](/packages/illuminate-http)[rdkafka/rdkafka

A PHP extension for Kafka

2.2k24.3k1](/packages/rdkafka-rdkafka)[httpsoft/http-message

Strict and fast implementation of PSR-7 and PSR-17

87965.9k114](/packages/httpsoft-http-message)[mezzio/mezzio-router

Router subcomponent for Mezzio

265.4M87](/packages/mezzio-mezzio-router)[serpapi/google-search-results-php

Get Google, Bing, Baidu, Ebay, Yahoo, Yandex, Home depot, Naver, Apple, Duckduckgo, Youtube search results via SerpApi.com

69127.2k](/packages/serpapi-google-search-results-php)

PHPackages © 2026

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