masakielastic / polling
Reference implementation of the PHP RFC Polling API using stream_select().
0.1.0
2026-03-03 06:28 UTC
Requires
- php: ^8.2
README
masakielastic/polling is a Composer-installable reference implementation for the PHP RFC Polling API.
Install
composer require masakielastic/polling
Status
This package currently provides a stream_select()-based implementation.
Io\Poll\Backend::Pollis available.Io\Poll\Backend::Autoresolves toPoll.StreamPollHandleis the only supported handle type.Event::EdgeTriggeredis not supported.
Usage
<?php declare(strict_types=1); require __DIR__ . '/vendor/autoload.php'; use Io\Poll\Context; use Io\Poll\Event; use Io\Poll\StreamPollHandle; $context = new Context(); $stream = fopen('php://temp', 'r+'); fwrite($stream, "hello\n"); rewind($stream); $watcher = $context->add(new StreamPollHandle($stream), [Event::Read], 'demo'); $ready = $context->wait(0, 1000); foreach ($ready as $triggered) { var_dump($triggered->getData(), $triggered->getTriggeredEvents()); }
Examples
Run them from the repository root after installing dependencies:
php examples/basic_tcp_server.php php examples/basic_tcp_client.php
Development
composer validate
composer test