PHPackages                             toknot/php-epoll - 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. toknot/php-epoll

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

toknot/php-epoll
================

PHP bindings to the linux epoll C API.

0.3.1(4mo ago)32234BSD-3-ClausePHPPHP &gt;=7.4.0

Since Mar 12Pushed 1mo ago1 watchersCompare

[ Source](https://github.com/chopins/php-epoll)[ Packagist](https://packagist.org/packages/toknot/php-epoll)[ Docs](http://toknot.com)[ RSS](/packages/toknot-php-epoll/feed)WikiDiscussions master Synced 3d ago

READMEChangelog (5)DependenciesVersions (6)Used By (0)

php-epoll
=========

[](#php-epoll)

PHP bindings to the linux epoll API.

### Requirements

[](#requirements)

- PHP &gt;= 7.4
- PHP FFI extension available
- Linux &gt; 2.6

### Install

[](#install)

use composer install:

```
composer require toknot/php-epoll

```

include composer autoload file : `./vendor/autoload.php`

Reference
---------

[](#reference)

- `Epoll::__construct()`
- `Epoll::create(int $flags)`

    open an epoll file descriptor
- `Epoll::ctl(int $op, int $fd, EpollEvent $events): int`

    control interface for an epoll file descriptor
- `Epoll::wait(EpollEvent $event, int $maxevents, int $timeout, $sigmask = null): int`

    wait for an I/O event on an epoll file descriptor
- `Epoll::getFdno(resource $file): int`

    get id from file descriptor of php resource (support file and php net socket)
- `Epoll::lastErrno(): int`

    get last error code
- `Epoll::lastError(): string`

    get last error message
- `Epoll::ffi(): FFI`
- `Epoll::initEvents($num): EpollEvent`
- `EpollEvent::__construct(Epoll $epoll,$num)`
- `EpollEvent::setEvent($event, $idx)`

    set Epoll events
- `EpollEvent::setData($data, $idx)`

    set user data variable
- `EpollEvent::getEvents($idx): FFI\CData`

Simple Example
--------------

[](#simple-example)

php resource to file descriptor

```
$epoll = new Epoll();
$fp = fopen(__FILE__, 'rb');
$fdno = $epoll->getFdno($fp, Epoll::RES_TYPE_FILE);
$fdfp = fopen("php://fd/$fdno", 'rb');
echo fread($fdfp, 1024);
```

epoll example from `man epoll`

```
const MAX_EVENTS = 10;
const EXIT_FAILURE = 1;

$epoll = new Epoll();
$ev = $epoll->initEvents(MAX_EVENTS);
$events = $epoll->initEvents();
$stream = stream_socket_server("tcp://0.0.0.0:8000", $errno, $errstr);
$listen_sock = $epoll->getFdno($stream, Epoll::RES_TYPE_NET);

function perror($str) {
    fprintf(STDERR, $str);
}

$epollfd = $epoll->create(0);

$ev->setEvent(Epoll::EPOLLIN);
$ev->setData(['fd' => $listen_sock]);

if ($epoll->ctl(Epoll::EPOLL_CTL_ADD, $listen_sock, $ev) == -1) {
    perror("epoll_ctl: listen_sock");
    exit(EXIT_FAILURE);
}

for (;;) {
    $nfds = $epoll->wait($events, MAX_EVENTS, -1);
    if ($nfds == -1) {
        perror("epoll_wait");
        exit(EXIT_FAILURE);
    }

    for ($n = 0; $n < $nfds; ++$n) {
        if ($events[$n]->data->fd == $listen_sock) {
            $conn_sock = stream_socket_accept($stream);
            if (!$conn_sock) {
                perror("accept");
                exit(EXIT_FAILURE);
            }
            stream_set_blocking($conn_sock, false);
            $ev->setEvent(Epoll::EPOLLIN | Epoll::EPOLLET);
            $connFdno = $epoll->getFdno($conn_sock, Epoll::RES_TYPE_NET);
            $ev->setData(['fd' => $connFdno]);
            if ($epoll->ctl(Epoll::EPOLL_CTL_ADD, $connFdno,
                        $ev) == -1) {
                perror("epoll_ctl: conn_sock");
                exit(EXIT_FAILURE);
            }
        } else {
            do_use_fd($events[$n]->data->fd);
        }
    }
}
```

###  Health Score

43

—

FairBetter than 91% of packages

Maintenance83

Actively maintained with recent releases

Popularity18

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity50

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

Every ~526 days

Total

5

Last Release

149d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/3683f29364f9fba39ebd7e90377b67c28ca2497e01cefc19ebb40df6cda72ddb?d=identicon)[szopen](/maintainers/szopen)

---

Top Contributors

[![chopins](https://avatars.githubusercontent.com/u/1539465?v=4)](https://github.com/chopins "chopins (39 commits)")

---

Tags

asynchronousepolleventffilinuxphpphpasynchronouseventsffiepoll

### Embed Badge

![Health badge](/badges/toknot-php-epoll/health.svg)

```
[![Health](https://phpackages.com/badges/toknot-php-epoll/health.svg)](https://phpackages.com/packages/toknot-php-epoll)
```

###  Alternatives

[jaxon-php/jaxon-core

Jaxon is an open source PHP library for easily creating Ajax web applications

73142.3k25](/packages/jaxon-php-jaxon-core)

PHPackages © 2026

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