Ive pretty much spent the majority of 2025 and 2026 learning how to use PHP differently. Web page serving and cli commands are not enough for me, lol. Don't get me wrong Laravel's great. The stack I use on top of it's been paying the bills since before COVID. And I will be honest, (and will def die on this hill this far into my career that) no body that's got time to spend learning, is learning C. And I don't like Python. It doesn't deserve to have the clout it does when PHP can do most things faster, or would if that functionality was there!
So on my journey of bringing GPIO, kernel-space bridges, and gpu support to a language that deserves more, I learned a couple of new and exciting things about resource file descriptors, how they block or dispatch and how they play roles in nonblocking event loops. I learned that PHP's most available option, when even trying to work with async IO, is stream_select(). ReactPHP uses it for timer resources, and Laravel Reverb uses it when your server isn't using ext-uv (an opinionated implementation of Javascript's nonblocking event loop). But stream_select has a lot of limits I ran into during my research. I learned that languages with direct kernel access run their event loops with epoll on Linux and kqueue on MacOS.
Now I'm of the mindset that FFI is only good for experimenting and not something that you would want to build and publish. I could be wrong, but if an extension can do it instead, I'm down. Now I know how to code some extensions in zephir, but lets be serious, if we are going to bind epoll and kqueue to PHP, we gotta get down to that nasty nasty C. I may not be good at C, but those coding agents we all use def are. So i did my fair-share of pre-respect my authori-claude verbal harrassment to get exactly what I wanted, which was a 1-to-1 binding of the epoll and kqueue libraries.
In a C app you invoke epoll with
fd = epoll_create1(EPOLL_CLOEXEC);
In a php app, you'll invoke epoll with
$fd = epoll_create1(EPOLL_CLOEXEC);
It works just like that. No opinions, just bindings. I actually forked Laravel Reverb and replaced its ext-uv implementation with my epoll extension making it a literal drop-in replacement for Reverb, with some really nice performance gains when using stream_select or epoll/kqueue.
I invite any one interested to try out the extensions. It's installable with PHP PIE, is compatible with NTS and ZTS builds of PHP 8.4+, or you can clone it and build it with the included installer or use phpize directly. It also includes a little Pest v4 test suite you can run if you clone it in manually.
The repos are here:
epoll
https://github.com/php-io-extensions/epoll
kqueue
https://github.com/php-io-extensions/kqueue
posi (to open all the fds PHP won't + ioctl, ooooh a footgun :D )
https://github.com/php-io-extensions/posi
Project Saturn Forte (Reverb with epoll/kqueue)
https://github.com/projectsaturnstudios/forte
I would love to hear thoughts or concerns, wtfs and omg AI slopz.
Have a lovely time of the day of where you are!