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?

Nick
  • 763
  • 1
  • 11
  • 26
  • 2
    [`stream_select()`](http://php.net/manual/en/function.stream-select.php) and [`socket_select()`](http://php.net/manual/en/function.socket-select.php) already exist - what are you trying to do that can't be achieved using one of those two? – DaveRandom Mar 07 '12 at 17:05
  • 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? – Itay Grudev Mar 07 '12 at 17:12
  • @DaveRandom Performance ... reliability .... – Nick Feb 08 '13 at 21:02
  • 1
    @DaveRandom "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`. – Daniel W. Feb 28 '14 at 10:48

3 Answers3

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).

fons
  • 4,905
  • 4
  • 29
  • 49
  • I added a comment mentioning Robert Love's analysis of inotify – fons Feb 14 '13 at 22:37
  • This is very interesting indeed, that said it appears you still need to poll an inotify descriptor correct? – Nick Feb 15 '13 at 16:25
  • 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. – fons Feb 16 '13 at 02:51
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.

igorw
  • 27,759
  • 5
  • 78
  • 90
  • 1
    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. – Nick Jul 06 '12 at 15:15
  • 1
    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. :) – igorw Jul 06 '12 at 15:51
  • 2
    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? – Nick Jul 06 '12 at 18:55
  • 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) – itsid Feb 11 '13 at 23:37
  • @itsid We're talking about [the libevent PHP extension](http://pecl.php.net/libevent). – igorw Feb 12 '13 at 00:17
  • Now you're just asking random questions. There is a libuv PHP extension. Google it. – igorw Feb 12 '13 at 18:22
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.

Daniel W.
  • 31,164
  • 13
  • 93
  • 151
  • 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 :) – Nick Feb 28 '14 at 15:10