PHPackages                             stratadox/observation-queue - 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. [Queues &amp; Workers](/categories/queues)
4. /
5. stratadox/observation-queue

ActiveLibrary[Queues &amp; Workers](/categories/queues)

stratadox/observation-queue
===========================

v0.1(8y ago)06MITPHPPHP &gt;=7.1

Since Jan 26Pushed 8y ago1 watchersCompare

[ Source](https://github.com/Stratadox/ObservationQueue)[ Packagist](https://packagist.org/packages/stratadox/observation-queue)[ RSS](/packages/stratadox-observation-queue/feed)WikiDiscussions master Synced 2mo ago

READMEChangelogDependencies (3)Versions (2)Used By (0)

Observation Queue
=================

[](#observation-queue)

[![Build Status](https://camo.githubusercontent.com/1e22f7bdc4d672f6414c11a962f94f8316674491b7e90100b15cb8f024ee6b12/68747470733a2f2f7472617669732d63692e6f72672f537472617461646f782f4f62736572766174696f6e51756575652e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/Stratadox/ObservationQueue)[![Coverage Status](https://camo.githubusercontent.com/8d6f1708d42d0ba343a11794ab4222477f4dcf7a0eef89dada7bb30e18855bce/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f537472617461646f782f4f62736572766174696f6e51756575652f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/github/Stratadox/ObservationQueue?branch=master)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/fb3cfe257a7d5b36ad84c10bca5d8a71529b1026f87221075b44734078bfd5eb/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f537472617461646f782f4f62736572766174696f6e51756575652f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/Stratadox/ObservationQueue/?branch=master)

Safeguard for observers to prevent problems in the invocation order.

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

[](#installation)

Install using composer:

`composer require stratadox/observation-queue`

Why use this?
-------------

[](#why-use-this)

Use this if you have situations where observers and observables are heavily used.

Observers, by default, come with a few pretty tricky gotcha's. Reentry, for instance, may cause bugs that can get pretty difficult to find.

### Example

[](#example)

Let's take a look at the following scenario:

```
We have two observables, Foo and Bar.
Observer A observes Foo, triggering Bar on update.
Observer B observes both Foo and Bar.
Foo gets triggered.

```

### What happens here?

[](#what-happens-here)

Since `Observer A` got registered to `Foo` before `Observer B` got registered, `Observer A` is updated first. Updating `Observer A` triggers `Bar`, which in turn leads to `Bar` updating its subscribers.

Makes sense for far, right? But here's the tricky part: At this point, *`Foo` has not yet updated `Observer B`!*

Of course, `Observer B` will *eventually* get updated by `Foo`. But only **after**receiving the update from `Bar`.

### The alternative

[](#the-alternative)

In situations where an Observer can trigger an update to an Observable, and the execution order of the relevant observers is of some importance, it may be wise to use the ObservationQueue.

The ObservationQueue is a queue of all the messages that still need to be sent to the observers. Observables add their items to the queue, and proceed to trigger the execution of the queue.

Due to this queueing layer, observer notifications are processed in the order in which the observables got triggered.

### What's the price?

[](#whats-the-price)

Although the monetary price of the software is zero, using this mechanism does introduce some shared mutable state. In order for the queue to have any effect, multiple observables need to be given access.

Basic use
---------

[](#basic-use)

Normally, updating the subscribers of an Observable would go roughly like this:

```
foreach ($this->subscribers as $subscriber) {
    $subscriber->notify($this);
}
```

When using an observation queue, instead use:

```
foreach ($this->subscribers as $subscriber) {
    $this->queue->add($subscriber, 'notify', $this);
}
$this->queue->trigger();
```

###  Health Score

22

—

LowBetter than 22% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity48

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.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

3025d ago

### Community

Maintainers

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

---

Top Contributors

[![Stratadox](https://avatars.githubusercontent.com/u/5333260?v=4)](https://github.com/Stratadox "Stratadox (16 commits)")

---

Tags

messagesobservableobservationsobserverobserver-patternqueuereentrant

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/stratadox-observation-queue/health.svg)

```
[![Health](https://phpackages.com/badges/stratadox-observation-queue/health.svg)](https://phpackages.com/packages/stratadox-observation-queue)
```

###  Alternatives

[league/geotools

Geo-related tools PHP 7.3+ library

1.4k5.3M26](/packages/league-geotools)[amphp/parser

A generator parser to make streaming parsers simple.

14952.8M16](/packages/amphp-parser)[amphp/serialization

Serialization tools for IPC and data storage in PHP.

13451.1M18](/packages/amphp-serialization)[enqueue/enqueue

Message Queue Library

19820.0M56](/packages/enqueue-enqueue)[deliciousbrains/wp-background-processing

WP Background Processing can be used to fire off non-blocking asynchronous requests or as a background processing tool, allowing you to queue tasks.

1.1k409.8k6](/packages/deliciousbrains-wp-background-processing)[react/async

Async utilities and fibers for ReactPHP

2238.8M170](/packages/react-async)

PHPackages © 2026

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