From 76f3f0a9d30e38a545f40a49d6569a2ad3af972a Mon Sep 17 00:00:00 2001 From: Niklas Keller Date: Sat, 14 Nov 2026 19:21:39 +0100 Subject: [PATCH 1/2] Report IoPollDriver as supported on the Io\Poll polyfill isSupported() now reports whether the driver can run, which includes symfony/polyfill-io-poll below PHP 8.6, also on Windows, where the polyfill is backed by stream_select() instead of WSAPoll. DriverFactory still only picks the driver automatically on PHP 8.6+, as the polyfill is slower than StreamSelectDriver. The tests now skip based on isSupported(), and a Windows job with the polyfill verifies it works there. The README mentions the driver. Co-Authored-By: Claude Opus 5.5 --- .github/workflows/ci.yml | 11 ++++++++++- README.md | 3 +++ src/EventLoop/Driver/IoPollDriver.php | 22 +++++++++++++--------- src/EventLoop/DriverFactory.php | 4 +++- test/Driver/IoPollDriverTest.php | 16 ++++------------ 5 files changed, 33 insertions(+), 23 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8d3a0003..09dfc816 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -44,7 +44,7 @@ jobs: io-poll-polyfill: 'yes' psalm: 'skip' - # kqueue and WSAPoll back IoPollDriver there, instead of epoll + # kqueue backs IoPollDriver on macOS instead of epoll; on Windows, the IoPollDriver tests are skipped (WSAPoll) - operating-system: 'macos-latest' php-version: 8.6 composer-flags: '--ignore-platform-req=php+' @@ -59,6 +59,15 @@ jobs: extensions: ':xdebug' psalm: 'skip' + # the polyfill is backed by stream_select() instead of WSAPoll, so IoPollDriver is supported there + - operating-system: 'windows-latest' + php-version: 8.4 + composer-flags: '--ignore-platform-req=php+' + job-description: 'on Windows with the Io\Poll polyfill' + io-poll-polyfill: 'yes' + extensions: ':xdebug' + psalm: 'skip' + name: PHP ${{ matrix.php-version }} ${{ matrix.job-description }} runs-on: ${{ matrix.operating-system }} diff --git a/README.md b/README.md index 23489e0a..8d85c36c 100644 --- a/README.md +++ b/README.md @@ -28,6 +28,9 @@ composer require revolt/event-loop ``` Applications with many concurrent file descriptors require one of the [extensions](https://revolt.run/extensions). +On PHP 8.6 and later, the built-in `Io\Poll` API (epoll, kqueue, …) is used automatically if no extension is available, except on Windows. +On older versions, `IoPollDriver` also works with [`symfony/polyfill-io-poll`](https://github.com/symfony/polyfill-io-poll), but is not selected automatically, as the polyfill is backed by `stream_select()`. +Set `REVOLT_DRIVER=Revolt\EventLoop\Driver\IoPollDriver` to use it anyway. →  [View documentation](https://revolt.run/)
diff --git a/src/EventLoop/Driver/IoPollDriver.php b/src/EventLoop/Driver/IoPollDriver.php index 6317471a..5f16e200 100644 --- a/src/EventLoop/Driver/IoPollDriver.php +++ b/src/EventLoop/Driver/IoPollDriver.php @@ -35,20 +35,24 @@ final class IoPollDriver extends AbstractDriver ]; /** - * Whether this driver is worth choosing over StreamSelectDriver. + * Whether this driver can run in the current environment. * - * The Io\Poll API ships with every PHP 8.6 build. The driver also runs on symfony/polyfill-io-poll - * below that, but that polyfill is backed by stream_select() itself, so it is slower than using - * stream_select() directly and is not picked automatically. Set REVOLT_DRIVER to this class to - * use it there anyway. + * The Io\Poll API ships with every PHP 8.6 build. Below that, the driver runs on + * symfony/polyfill-io-poll (with symfony/polyfill-time). That polyfill is backed by stream_select() + * itself, so it is slower than StreamSelectDriver, and DriverFactory only picks this driver + * automatically on PHP 8.6+. Set REVOLT_DRIVER to this class to use it with the polyfill anyway. * - * On Windows, the only backend is WSAPoll, which accepts pipes such as STDOUT, but never reports - * them, so callbacks on them never run. stream_select() handles them, so the driver is not - * supported there for now. + * On Windows with PHP 8.6+, the only native backend is WSAPoll, which accepts pipes such as + * STDOUT, but never reports them, so callbacks on them never run. stream_select() handles them, + * so the driver is not supported there for now. */ public static function isSupported(): bool { - return \PHP_VERSION_ID >= 80600 && \PHP_OS_FAMILY !== 'Windows'; + if (\PHP_VERSION_ID >= 80600) { + return \PHP_OS_FAMILY !== 'Windows'; + } + + return \class_exists(Context::class) && \class_exists(Duration::class); } private readonly Context $context; diff --git a/src/EventLoop/DriverFactory.php b/src/EventLoop/DriverFactory.php index efd8bd3b..75ff4d07 100644 --- a/src/EventLoop/DriverFactory.php +++ b/src/EventLoop/DriverFactory.php @@ -40,7 +40,9 @@ public function create(): Driver return new EventDriver(); } - if (IoPollDriver::isSupported()) { + // Below PHP 8.6, IoPollDriver runs on symfony/polyfill-io-poll, which is backed by + // stream_select() and therefore slower than StreamSelectDriver. + if (\PHP_VERSION_ID >= 80600 && IoPollDriver::isSupported()) { return new IoPollDriver(); } diff --git a/test/Driver/IoPollDriverTest.php b/test/Driver/IoPollDriverTest.php index 2b5c371b..4d9799a1 100644 --- a/test/Driver/IoPollDriverTest.php +++ b/test/Driver/IoPollDriverTest.php @@ -8,7 +8,6 @@ use Io\Poll\Context; use PHPUnit\Framework\ExpectationFailedException; use Revolt\EventLoop\Driver; -use Time\Duration; class IoPollDriverTest extends DriverTest { @@ -21,14 +20,8 @@ public function getFactory(): callable public function setUp(): void { - // Not isSupported(): that is deliberately false below 8.6, while the driver still has to be - // exercised there through the polyfill. - if (!\class_exists(Context::class) || !\class_exists(Duration::class)) { - self::markTestSkipped("Skip, the Io\\Poll API requires PHP 8.6 or symfony/polyfill-io-poll"); - } - - if (self::isWindows()) { - self::markTestSkipped("Skip on Windows, WSAPoll never reports pipes such as STDOUT, so tests hang"); + if (!IoPollDriver::isSupported()) { + self::markTestSkipped("IoPollDriver is not supported in this environment"); } parent::setUp(); @@ -199,9 +192,8 @@ public function testMoreFileDescriptorsThanFdSetSize(): void self::assertTrue($invoked); } - public function testSupportedOnlyWhenNativeAndNotOnWindows(): void + public function testSupportedIfTestsAreNotSkipped(): void { - // the polyfill runs the driver, but it is backed by stream_select() and slower than using it directly - self::assertSame(\PHP_VERSION_ID >= 80600 && !self::isWindows(), IoPollDriver::isSupported()); + self::assertTrue(IoPollDriver::isSupported()); } } From 3e2e07a690e52ca6d51aeecde3b69179d5f12cf3 Mon Sep 17 00:00:00 2001 From: Niklas Keller Date: Sat, 14 Nov 2026 19:43:59 +0100 Subject: [PATCH 2/2] Don't support IoPollDriver on Windows with the Io\Poll polyfill Winsock reports a failed non-blocking connect() only in select()'s except set, which the polyfill does not pass to stream_select(), so writable callbacks on such sockets never run. Treat Windows as unsupported for the polyfill too, like for native WSAPoll, and disable the Windows polyfill CI job until the polyfill handles this. Co-Authored-By: Claude Opus 5.5 --- .github/workflows/ci.yml | 18 ++++++++++-------- README.md | 2 +- src/EventLoop/Driver/IoPollDriver.php | 16 ++++++++++------ 3 files changed, 21 insertions(+), 15 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 09dfc816..014b44ef 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -59,14 +59,16 @@ jobs: extensions: ':xdebug' psalm: 'skip' - # the polyfill is backed by stream_select() instead of WSAPoll, so IoPollDriver is supported there - - operating-system: 'windows-latest' - php-version: 8.4 - composer-flags: '--ignore-platform-req=php+' - job-description: 'on Windows with the Io\Poll polyfill' - io-poll-polyfill: 'yes' - extensions: ':xdebug' - psalm: 'skip' + # IoPollDriver is not supported on Windows with the polyfill yet, as it never reports failed + # non-blocking connects there (Winsock only signals them in select()'s except set). Re-enable + # once the polyfill passes the except set to stream_select(). + # - operating-system: 'windows-latest' + # php-version: 8.4 + # composer-flags: '--ignore-platform-req=php+' + # job-description: 'on Windows with the Io\Poll polyfill' + # io-poll-polyfill: 'yes' + # extensions: ':xdebug' + # psalm: 'skip' name: PHP ${{ matrix.php-version }} ${{ matrix.job-description }} runs-on: ${{ matrix.operating-system }} diff --git a/README.md b/README.md index 8d85c36c..b5a0fe5c 100644 --- a/README.md +++ b/README.md @@ -29,7 +29,7 @@ composer require revolt/event-loop Applications with many concurrent file descriptors require one of the [extensions](https://revolt.run/extensions). On PHP 8.6 and later, the built-in `Io\Poll` API (epoll, kqueue, …) is used automatically if no extension is available, except on Windows. -On older versions, `IoPollDriver` also works with [`symfony/polyfill-io-poll`](https://github.com/symfony/polyfill-io-poll), but is not selected automatically, as the polyfill is backed by `stream_select()`. +On older versions (again except on Windows), `IoPollDriver` also works with [`symfony/polyfill-io-poll`](https://github.com/symfony/polyfill-io-poll), but is not selected automatically, as the polyfill is backed by `stream_select()`. Set `REVOLT_DRIVER=Revolt\EventLoop\Driver\IoPollDriver` to use it anyway. →  [View documentation](https://revolt.run/) diff --git a/src/EventLoop/Driver/IoPollDriver.php b/src/EventLoop/Driver/IoPollDriver.php index 5f16e200..9f209d53 100644 --- a/src/EventLoop/Driver/IoPollDriver.php +++ b/src/EventLoop/Driver/IoPollDriver.php @@ -42,17 +42,21 @@ final class IoPollDriver extends AbstractDriver * itself, so it is slower than StreamSelectDriver, and DriverFactory only picks this driver * automatically on PHP 8.6+. Set REVOLT_DRIVER to this class to use it with the polyfill anyway. * - * On Windows with PHP 8.6+, the only native backend is WSAPoll, which accepts pipes such as - * STDOUT, but never reports them, so callbacks on them never run. stream_select() handles them, - * so the driver is not supported there for now. + * The driver is not supported on Windows for now: + * - With PHP 8.6+, the only native backend is WSAPoll, which accepts pipes such as STDOUT, but + * never reports them, so callbacks on them never run. stream_select() handles them. + * - The polyfill never reports a failed non-blocking connect(), because Winsock signals that only + * in select()'s except set, which the polyfill does not pass to stream_select(), so writable + * callbacks on such sockets never run. StreamSelectDriver handles this. */ public static function isSupported(): bool { - if (\PHP_VERSION_ID >= 80600) { - return \PHP_OS_FAMILY !== 'Windows'; + if (\PHP_OS_FAMILY === 'Windows') { + return false; } - return \class_exists(Context::class) && \class_exists(Duration::class); + return \PHP_VERSION_ID >= 80600 + || (\class_exists(Context::class) && \class_exists(Duration::class)); } private readonly Context $context;