masakielastic/polling

Reference implementation of the PHP RFC Polling API using stream_select().

Maintainers

Package info

github.com/masakielastic/php-polling

pkg:composer/masakielastic/polling

Statistics

Installs: 0

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

0.1.0 2026-03-03 06:28 UTC

This package is auto-updated.

Last update: 2026-03-03 06:31:43 UTC


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::Poll is available.
  • Io\Poll\Backend::Auto resolves to Poll.
  • StreamPollHandle is the only supported handle type.
  • Event::EdgeTriggered is 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