PHPackages                             10up/async-transients - 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. [Caching](/categories/caching)
4. /
5. 10up/async-transients

AbandonedArchivedWordpress-library[Caching](/categories/caching)

10up/async-transients
=====================

Transients, that regenerate asynchronously once content is expired, and serve stale content in the mean time

1.0.0(8y ago)12417.7k—8.3%10[2 issues](https://github.com/10up/Async-Transients/issues)[1 PRs](https://github.com/10up/Async-Transients/pulls)MITPHP

Since Jan 9Pushed 1y ago12 watchersCompare

[ Source](https://github.com/10up/Async-Transients)[ Packagist](https://packagist.org/packages/10up/async-transients)[ RSS](/packages/10up-async-transients/feed)WikiDiscussions develop Synced 1mo ago

READMEChangelogDependenciesVersions (4)Used By (0)

Async Transients
================

[](#async-transients)

> Transients that serve stale data while regenerating the new transients in the background.

[![Support Level](https://camo.githubusercontent.com/bda18bd40847957c7c2fd168847c0be1c844a01a7e8938bbadef330bcd0f6790/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f737570706f72742d61726368697665642d7265642e737667)](#support-level) [![Release Version](https://camo.githubusercontent.com/59900168645087e172c82384d2d2f2d7e3c4c0db6b5c27416900453ca34d7d97/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f7461672f313075702f4173796e632d5472616e7369656e74732e7376673f6c6162656c3d72656c65617365)](https://github.com/10up/Async-Transients/releases/latest) [![MIT License](https://camo.githubusercontent.com/1f2720e0e2f74a4917faeffd86041b5a76e98c9a8ef9770618529e24d936cfab/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f313075702f4173796e632d5472616e7369656e74732e737667)](https://github.com/10up/Async-Transients/blob/develop/LICENSE.md)

Caution

As of 12 April 2024, this project is archived and no longer being actively maintained.

Background &amp; Purpose
------------------------

[](#background--purpose)

Transients are great for storing data that is expensive to regenerate, but we still run in to the problem of needing to regenerate that data synchronously once the transient expires. This library solves that problem by serving stale data once the transient is expired, and processing the regenerate callback after the request has finished, so that end users never see the impact of regenerating transients.

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

[](#requirements)

Requires support for `fastcgi_finish_request`, or else transients will regenerate expired data immediately.

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

[](#installation)

This library is meant to be included with composer. To install, run `composer require 10up/async-transients`. The library is set up to use composer's autoloader, so make certain you are loading your `vendor/autoload.php` file.

Usage
-----

[](#usage)

Usage is similar to standard WordPress transient functions, in that you provide a transient key and an expiration time, but its different in that you must also provide a callback function, as well as any (optional) parameters to pass to the callback function, that should be called to regenerate the transient data if it is expired.

Example Usage:

```
// Function to regenerate expired transient
function get_data_from_api( $user_id ) {
	// Fake function, that we assume is really time consuming to run
	$my_result = get_api_data_for_user( $user_id );

	\TenUp\AsyncTransients\set_async_transient( 'transient-key-' . $user_id, $my_result, MINUTE_IN_SECONDS );
}

// This would very likely not be hardcoded...
$user_id = 1;

// If the transient is expired get_data_from_api() is called, with $user_id as a parameter
$transient_value = \TenUp\AsyncTransients\get_async_transient( 'transient-key-' . $user_id, 'get_data_from_api', array( $user_id ) );

// Outputs the value stored in the transient
// If the transient is expired, it will still show the last known data, while queueing the transient to be updated behind the scenes.
var_dump( $transient_value );
```

How does all of this work?
--------------------------

[](#how-does-all-of-this-work)

First, when calling `get_async_transient`, you now have to pass a callback function, and optionally, any parameters to pass to the callback function. The transient is then retrieved, much like how WordPress core would retrieve it, but with a key difference. Instead of returning nothing if the transient is expired, we return the last known value, and add the callback function and params to a queue, to process later. By the end of the request, we have a queue of that contains callback functions for all transients that were accessed, that had expired data.

Next, we hook into the WordPress `shutdown` action. The `shutdown` action runs just before PHP shuts down execution. The Transient class hooks into that action, and calls the [`fastcgi_finish_request` function](http://php.net/manual/en/function.fastcgi-finish-request.php), if it is available. That function flushes all response data to the client, and as far as the browser is concerned, the request is done, however, php is allowed to keep running in the background.

At this point, we iterate over all the callback functions in the queue, which then regenerate any transient data that was accessed, but was expired.

Issues
------

[](#issues)

If you identify any errors or have an idea for improving the plugin, please [open an issue](https://github.com/10up/Async-Transients/issues). We're excited to see what the community thinks of this project, and we would love your input!

Support Level
-------------

[](#support-level)

**Archived:** This project is no longer maintained by 10up. We are no longer responding to Issues or Pull Requests unless they relate to security concerns. We encourage interested developers to fork this project and make it their own!

Like what you see?
------------------

[](#like-what-you-see)

[![](https://camo.githubusercontent.com/5ec5223fa6fe20a5ca00d8d768bd7ee91e93f67c9d7a06e575c87e3ed1d00263/68747470733a2f2f313075702e636f6d2f75706c6f6164732f323031362f31302f313075702d4769746875622d42616e6e65722e706e67)](http://10up.com/contact/)

###  Health Score

44

—

FairBetter than 92% of packages

Maintenance33

Infrequent updates — may be unmaintained

Popularity43

Moderate usage in the ecosystem

Community19

Small or concentrated contributor base

Maturity65

Established project with proven stability

 Bus Factor1

Top contributor holds 56% 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

Unknown

Total

1

Last Release

3051d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/3358927?v=4)[10up](/maintainers/10up)[@10up](https://github.com/10up)

---

Top Contributors

[![cmmarslender](https://avatars.githubusercontent.com/u/1915905?v=4)](https://github.com/cmmarslender "cmmarslender (14 commits)")[![jeffpaul](https://avatars.githubusercontent.com/u/2818133?v=4)](https://github.com/jeffpaul "jeffpaul (9 commits)")[![salcode](https://avatars.githubusercontent.com/u/5194588?v=4)](https://github.com/salcode "salcode (1 commits)")[![tlovett1](https://avatars.githubusercontent.com/u/1844351?v=4)](https://github.com/tlovett1 "tlovett1 (1 commits)")

---

Tags

archived

### Embed Badge

![Health badge](/badges/10up-async-transients/health.svg)

```
[![Health](https://phpackages.com/badges/10up-async-transients/health.svg)](https://phpackages.com/packages/10up-async-transients)
```

###  Alternatives

[react/cache

Async, Promise-based cache interface for ReactPHP

444112.4M40](/packages/react-cache)[wp-media/wp-rocket

Performance optimization plugin for WordPress

7431.3M3](/packages/wp-media-wp-rocket)[illuminate/cache

The Illuminate Cache package.

12835.6M1.4k](/packages/illuminate-cache)[colinmollenhour/php-redis-session-abstract

A Redis-based session handler with optimistic locking

6325.6M14](/packages/colinmollenhour-php-redis-session-abstract)[cheprasov/php-redis-client

Php client for Redis. It is a fast, fully-functional and user-friendly client for Redis, optimized for performance. RedisClient supports the latest versions of Redis starting from 2.6 to 6.0

1281.2M21](/packages/cheprasov-php-redis-client)[amphp/redis

Efficient asynchronous communication with Redis servers, enabling scalable and responsive data storage and retrieval.

165634.7k44](/packages/amphp-redis)

PHPackages © 2026

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