Skip to content

[Php86] Polyfill the Io\Poll API#612

Open
nicolas-grekas wants to merge 1 commit into
1.xfrom
polyfill-io-poll
Open

[Php86] Polyfill the Io\Poll API#612
nicolas-grekas wants to merge 1 commit into
1.xfrom
polyfill-io-poll

Conversation

@nicolas-grekas
Copy link
Copy Markdown
Member

Tracks the Polling API RFC targeted at PHP 8.6.

Surface added under src/Php86/Resources/stubs/:

  • Io\IoException, Io\Poll\PollException, abstract FailedPollOperationException (with ERROR_* constants), and the seven specialized exceptions (Failed{ContextInitialization,HandleAdd,WatcherModification,PollWait}Exception, BackendUnavailableException, InactiveWatcherException, HandleAlreadyWatchedException, InvalidHandleException).
  • Io\Poll\Backend enum with Auto, Poll, Epoll, Kqueue, EventPorts, WSAPoll cases and isAvailable() / supportsEdgeTriggering() / getAvailableBackends().
  • Io\Poll\Event enum with Read, Write, Error, HangUp, ReadHangUp, OneShot, EdgeTriggered.
  • Io\Poll\Handle marker interface (annotated @internal to discourage userland implementations).
  • Final Io\Poll\Context, Io\Poll\Watcher, and global StreamPollHandle, with private constructors / not-serializable enforced via rebound Closures and throwing __serialize/__unserialize.

Requires PHP >= 8.1 (enums). Backed by stream_select(), so only the Poll backend is available; Auto resolves to it and the other backends throw BackendUnavailableException. HangUp detection on sockets uses stream_socket_recvfrom(..., STREAM_PEEK) to non-destructively distinguish "readable with data" from "peer closed".

35 unit tests cover the API surface and the event-detection logic.

@nicolas-grekas nicolas-grekas force-pushed the polyfill-io-poll branch 4 times, most recently from fbdae99 to 7e4b509 Compare May 25, 2026 16:30
Tracks https://wiki.php.net/rfc/poll_api for PHP 8.6. Requires PHP >= 8.1
(enums); only the Poll backend is available since the polyfill is backed
by stream_select().
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant