PHPackages                             phillipsdata/priority-schedule - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. phillipsdata/priority-schedule

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

phillipsdata/priority-schedule
==============================

A priority schedule library

1.0.2(10y ago)1909↓50%8MITPHPPHP &gt;=5.4.0

Since Mar 17Pushed 10y ago4 watchersCompare

[ Source](https://github.com/phillipsdata/priority-schedule)[ Packagist](https://packagist.org/packages/phillipsdata/priority-schedule)[ Docs](http://github.com/phillipsdata/priority-schedule)[ RSS](/packages/phillipsdata-priority-schedule/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (3)Dependencies (3)Versions (4)Used By (8)

Priority Schedule
=================

[](#priority-schedule)

[![Build Status](https://camo.githubusercontent.com/1b1088158d8ed8610d96abf7a34a5e062a6218548e989f9b373ef99745f300ad/68747470733a2f2f7472617669732d63692e6f72672f7068696c6c697073646174612f7072696f726974792d7363686564756c652e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/phillipsdata/priority-schedule)[![Coverage Status](https://camo.githubusercontent.com/60d9ddc9d0ffbfd17b773201ec5bbf7ad286a073f9777f36819d8bc0a08a99ec/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f7068696c6c697073646174612f7072696f726974792d7363686564756c652f62616467652e737667)](https://coveralls.io/r/phillipsdata/priority-schedule)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/4d23fa57e9deb25340a336b36e144050d1e1592742b9373f909823f35e6cc8ff/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f7068696c6c697073646174612f7072696f726974792d7363686564756c652f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/phillipsdata/priority-schedule/?branch=master)

A priority schedule library.

This library provides data structures for performing **Round Robin** and **First Available** access to items.

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

[](#installation)

```
composer require phillipsdata/priority-schedule
```

Usage
-----

[](#usage)

There are two built-in priority schedules:

1. **Round Robin**
    - Returns the item with the least weight such that the weight of each of the items is proportional.
2. **First Available**
    - Returns items in the order added added (FIFO) such that only valid items are returned.

### Round Robin

[](#round-robin)

The Round Robin schedule allows you retrieve items in an evenly distributed manner, by specifying a comparator that defines the priority for items returned.

Suppose you have 3 bucket objects:

BucketCountA0B2C4Assuming each time we retrieve a bucket we increment its count, then add it back to the schedule, we would expect to retrieve buckets in the following order:

```
A, A, A, B, B, A, A, C, B

```

```
use PhillipsData\PrioritySchedule\RoundRobin;

// Create our buckets
$a = new stdClass();
$a->name = 'A';
$a->count = 0;

$b = new stdClass();
$b->name = 'B';
$b->count = 2;

$c = new stdClass();
$c->name = 'C';
$c->count = 4;

// Initialize the priority schedule with a custom comparator
$rr = new RoundRobin();
$rr->setCallback(function ($x, $y) {
    if ($x->count === $y->count) {
        return 0;
    }
    // we want low items first so they have higher (1) priority
    return $x->count < $y->count
        ? 1
        : -1;
});

// Add items to the schedule
$rr->insert($a);
$rr->insert($b);
$rr->insert($c);

// Fetch items
foreach ($rr as $item) {
    echo $item->name . " (" . ++$item->count . ")\n";

    if ($item->count < 5) {
        $rr->insert($item);
    }
}
```

Output:

```
A (1)
A (2)
A (3)
B (3)
B (4)
A (4)
A (5)
C (5)
B (5)

```

### First Available

[](#first-available)

The First Available schedule allows you to retrieve elements in the order in which they were added (FIFO), skipping elements that are not eligible (think of the line to get into a night club) using a callback.

Suppose you have 3 bucket objects:

BucketCountA0B2C4Assuming each time we retrieve a bucket we decrement its count, then add it back to the schedule, we would expect to retrieve buckets in the following order:

```
B, C, B, C, C, C

```

This is because once a bucket reaches `0` we no longer consider it valid.

```
use PhillipsData\PrioritySchedule\FirstAvailable;

// Create our buckets
$a = new stdClass();
$a->name = 'A';
$a->count = 0;

$b = new stdClass();
$b->name = 'B';
$b->count = 2;

$c = new stdClass();
$c->name = 'C';
$c->count = 4;

// Initialize the priority schedule with a custom filter
$fa = new FirstAvailable();
$fa->setCallback(function ($item) {
    return $item->count > 0;
});

// Add items to the schedule
$fa->insert($a);
$fa->insert($b);
$fa->insert($c);

foreach ($fa as $item) {
    echo $item->name . " (" . --$item->count . ")\n";

    if ($item->count > 0) {
        $fa->insert($item);
    }
}
```

Output:

```
B (1)
C (3)
B (0)
C (2)
C (1)
C (0)

```

###  Health Score

32

—

LowBetter than 72% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity19

Limited adoption so far

Community19

Small or concentrated contributor base

Maturity60

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 ~3 days

Total

3

Last Release

3707d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/7f87ae869d67f48673504d6cba1adcb8945a3ba8280798917e18b7c744009fc2?d=identicon)[clphillips](/maintainers/clphillips)

![](https://www.gravatar.com/avatar/e1100c7dbee65c40edf82c25a4b7d5a34bd677ff86263396ca2ac5163da1dbe0?d=identicon)[tysonphillips](/maintainers/tysonphillips)

![](https://www.gravatar.com/avatar/b73da57e4fcb22c7d7f459b2bd00ea7bceb6252df0cd14e2d0bf4b6a145709fc?d=identicon)[paulphillips](/maintainers/paulphillips)

---

Top Contributors

[![clphillips](https://avatars.githubusercontent.com/u/682986?v=4)](https://github.com/clphillips "clphillips (11 commits)")

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/phillipsdata-priority-schedule/health.svg)

```
[![Health](https://phpackages.com/badges/phillipsdata-priority-schedule/health.svg)](https://phpackages.com/packages/phillipsdata-priority-schedule)
```

PHPackages © 2026

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