PHPackages                             om3rcitak/ip-set - 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. om3rcitak/ip-set

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

om3rcitak/ip-set
================

Efficiently match IP addresses against a set of CIDR specifications.

3.1.2(4y ago)241GPL-2.0-or-laterPHPPHP &gt;=7.2.9

Since Jun 26Pushed 4y agoCompare

[ Source](https://github.com/om3rcitak/IPSet)[ Packagist](https://packagist.org/packages/om3rcitak/ip-set)[ Docs](https://www.mediawiki.org/wiki/IPSet)[ RSS](/packages/om3rcitak-ip-set/feed)WikiDiscussions master Synced 4w ago

READMEChangelog (2)Dependencies (8)Versions (15)Used By (0)

IPSet
=====

[](#ipset)

***Note: This project is forked from Wikimedia/IPSet.***

IPSet is a PHP library for matching IP addresses against a set of CIDR specifications.

Here is how you use it:

```
use Om3rcitak\IPSet;
// At startup, calculate the optimized data structure for the set:
$ipset = new IPSet( [

    '208.80.154.0/26',
    '2620:0:861:1::/64',
    '10.64.0.0/22',

] );

// Runtime check against cached set (returns bool):
if ( $ipset->match( $ip ) ) {

    // ...

}
```

In rough benchmarking, this takes about 80% more time than `in_array()` checks on a short (a couple hundred at most) array of addresses. It's fast either way at those levels, though, and IPSet would scale better than in\_array if the array were much larger.

For mixed-family CIDR sets, however, this code gives well over 100x speedup vs iterating `Wikimedia\IPUtils::isInRange()` over an array of CIDR specs.

The basic implementation is two separate binary trees (IPv4 and IPv6) as nested php arrays with keys named 0 and 1. The values false and true are terminal match-fail and match-success, otherwise the value is a deeper node in the tree.

A simple depth-compression scheme is also implemented: whole-byte tree compression at whole-byte boundaries only, where no branching occurs during that whole byte of depth. A compressed node has keys 'comp' (the byte to compare) and 'next' (the next node to recurse into if 'comp' matched successfully).

For example, given these inputs:

```
25.0.0.0/9
25.192.0.0/10
```

The v4 tree would look like:

```
root4 => [

    'comp' => 25,
    'next' => [
        0 => true,
        1 => [
            0 => false,
            1 => true,
        ],
    ],

];
```

(multi-byte compression nodes were attempted as well, but were a net loss in my test scenarios due to additional match complexity)

License
-------

[](#license)

Copyright 2014, 2015 Brandon Black

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

###  Health Score

30

—

LowBetter than 64% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity11

Limited adoption so far

Community15

Small or concentrated contributor base

Maturity66

Established project with proven stability

 Bus Factor4

4 contributors hold 50%+ of commits

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

Recently: every ~211 days

Total

13

Last Release

1643d ago

Major Versions

1.2.0 → 2.0.02018-12-18

1.3.0 → 2.0.12019-02-11

2.1.0 → 3.0.02021-03-21

PHP version history (4 changes)1.0.0PHP &gt;=5.3.3

1.2.0PHP &gt;=5.5.9

2.0.0PHP &gt;=5.6.99

3.0.0PHP &gt;=7.2.9

### Community

Maintainers

![](https://www.gravatar.com/avatar/4866fe7d6b0290682b0c874e233755fa9904eda3bf202b9beb98b5c4eb2b5dce?d=identicon)[om3rcitak](/maintainers/om3rcitak)

---

Top Contributors

[![reedy](https://avatars.githubusercontent.com/u/67615?v=4)](https://github.com/reedy "reedy (11 commits)")[![legoktm](https://avatars.githubusercontent.com/u/81392?v=4)](https://github.com/legoktm "legoktm (8 commits)")[![umherirrender](https://avatars.githubusercontent.com/u/1174884?v=4)](https://github.com/umherirrender "umherirrender (7 commits)")[![om3rcitak](https://avatars.githubusercontent.com/u/5197413?v=4)](https://github.com/om3rcitak "om3rcitak (6 commits)")[![jdforrester](https://avatars.githubusercontent.com/u/881572?v=4)](https://github.com/jdforrester "jdforrester (6 commits)")[![Krinkle](https://avatars.githubusercontent.com/u/156867?v=4)](https://github.com/Krinkle "Krinkle (6 commits)")[![atdt](https://avatars.githubusercontent.com/u/376462?v=4)](https://github.com/atdt "atdt (3 commits)")[![ricordisamoa](https://avatars.githubusercontent.com/u/4588496?v=4)](https://github.com/ricordisamoa "ricordisamoa (3 commits)")[![plstand](https://avatars.githubusercontent.com/u/762731?v=4)](https://github.com/plstand "plstand (1 commits)")[![RazeSoldier](https://avatars.githubusercontent.com/u/29511518?v=4)](https://github.com/RazeSoldier "RazeSoldier (1 commits)")[![Daimona](https://avatars.githubusercontent.com/u/38216014?v=4)](https://github.com/Daimona "Daimona (1 commits)")[![bd808](https://avatars.githubusercontent.com/u/6469?v=4)](https://github.com/bd808 "bd808 (1 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/om3rcitak-ip-set/health.svg)

```
[![Health](https://phpackages.com/badges/om3rcitak-ip-set/health.svg)](https://phpackages.com/packages/om3rcitak-ip-set)
```

PHPackages © 2026

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