epoll, kqueue, /dev/poll .... extensions for PHP
Asked Answered
T

3

9

Is there a PHP extension (stability is irrelevant) that allows for direct epoll, kqueue, /dev/poll polling functions without going through libevent or libev extensions?

Theirs answered 7/3, 2012 at 16:57 Comment(4)
stream_select() and socket_select() already exist - what are you trying to do that can't be achieved using one of those two?Arthurarthurian
As far as I know polling is a very low based protocol in the OSI model. Therefore it shouldn't be accessible from a language based on the Presentation level. What exactly are you trying to achieve?Tyishatyke
@Arthurarthurian Performance ... reliability ....Theirs
@Arthurarthurian "It is meant to replace the older POSIX select(2) and poll(2) system calls, to achieve better performance in more demanding applications..." - socket_select() does a system call to select.Dusen
F
2

Inotify

You don't specify what architectures should be supported by the extension. But if Linux-only is an option you can use inotify, which:

  • seems to have a more stable extension
  • provides similar functionality.

php-inotifytools is a another possible extension.

Here is an extensive, self-contained article showing how inotify works and how to use the C API.

Additionally, judging by by the conclusion of Robert Love's article: Intro to inotify, inotify has a very good performance:

inotify is a simple yet powerful file change notification system with an intuitive user interface, excellent performance, support for many different events and numerous features. inotify is currently in use in various projects, including Beagle, an advanced desktop indexing system, and Gamin, a FAM replacement.

Robert Love is a well respected Linux kernel hacker, and author of the reference book Linux Kernel Development (which I happen to own).

Florist answered 14/2, 2013 at 12:42 Comment(3)
I added a comment mentioning Robert Love's analysis of inotifyFlorist
This is very interesting indeed, that said it appears you still need to poll an inotify descriptor correct?Theirs
The file descriptor accumulates all the asynchronous events, so, even if you have to read it in order to obtain the events, no events won't be lost regardless of how often you check it. Inotify doesnt provide a callback mechanism (i guess that's what you are asking), but inotify's file descriptor is select-, poll-, epoll- and read-able. A simple callback system could be easily implemented with a dedicated thread.Florist
Z
0

Right now libevent is going to be the most stable thing you can get for PHP. It supports epoll as a backend.

There is also an experimental extension for libev. It is less stable than the libevent one, but has a nicer OO API.

Zoie answered 5/7, 2012 at 20:17 Comment(6)
As I mentioned I know of libevent and it does not have a stable release so it really is not a viable option nor would anything else that is not stable so I don't see how this answers my question and is more of a useful comment.Theirs
So you would not use an extension that has been in beta for 4 years, but you would use an extension you wrote yourself (and only supports epoll but no other backends)? Suit yourself. :)Zoie
Why would you use something that has not been actively developed for over 4 years and is still in a beta state for production level code?Theirs
I am sorry, am I missing something.. libevent is tagged stable since june 7th 2010 latest release is dated November (libevent-2.0.21-stable.tar.gz Released 2012-11-18) or is that some other libevent you're talking about? (libevent.org)Bouzoun
@Bouzoun We're talking about the libevent PHP extension.Zoie
Now you're just asking random questions. There is a libuv PHP extension. Google it.Zoie
D
0

There is a PECL extension providing the classes Event and EventBase which can work with several things and also with epoll.

See: http://www.php.net/manual/en/event.examples.php

Sorry I can't provide a sample other than you will find on the link because I didn't work with this yet.

EventBase class represents libevent's event base structure. It holds a set of events and can poll to determine which events are active.

Each event base has a method , or a backend that it uses to determine which events are ready. The recognized methods are: select , poll , epoll , kqueue , devpoll , evport and win32 .

To configure event base to use, or avoid specific backend EventConfig class can be used.

Dusen answered 28/2, 2014 at 10:51 Comment(1)
From the intro "This is a port of libevent to the PHP infrastructure." ... I am searching for an extension that does not require the use of libevent or libev for that matter as a backend and provides straight access to epoll, kqueue or /dev/poll that I can directly poll in PHP just as you can now using select, thanks for the response though :)Theirs

© 2022 - 2024 — McMap. All rights reserved.