|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #59370 event_base_loop with EVLOOP_NONBLOCK not raising events
Submitted: 2010-08-17 08:29 UTC Modified: 2013-01-31 19:04 UTC
From: noniazzi at profideo dot com Assigned: tony2001 (profile)
Status: Not a bug Package: libevent (PECL)
PHP Version: 5.3.2 OS: Ubuntu 10.4
Private report: No CVE-ID: None
 [2010-08-17 08:29 UTC] noniazzi at profideo dot com
When using event_base_loop with the flag EVLOOP_NONBLOCK, the callback doesn't seem to be called.

Reproduce code:

$base  = event_base_new();
$event = event_new();

event_set($event, STDIN, EV_READ, "ev_read", array($event, $base));
event_base_set($event, $base);
event_base_loop($base, EVLOOP_NONBLOCK);

for ($i = 10000000; $i > 0; $i--) {
  // do something here

echo "End\n";

function ev_read($fd, $events, $arg = null) {
  $data = trim(fgets($fd));
  echo "read: [" . $data . "]\n";
$ php example.php

Expected result:
read: [foo]

Actual result:
$ foo
foo: command not found


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2011-02-16 16:53 UTC] evert at rooftopsolutions dot nl
I think you're misunderstanding how libevent works, for two reasons:

1. libevent does not work asynchonously. Because of your loop, it seems as if you expect the event to be triggered while your loop is still running. 

2. EVLOOP_NONBLOCK just means you start the event loop, but return immediately if there were no pending events. Since you haven't typed 'foo' yet, the event is not triggered.
 [2013-01-25 08:53 UTC]
-Status: Open +Status: Assigned -Assigned To: +Assigned To: tony2001
 [2013-01-31 19:04 UTC]
-Status: Assigned +Status: Not a bug
 [2013-01-31 19:04 UTC]
Yes, Evert is certainly right here.
You have to poll the events with the event loop, otherwise how you're going to know 
when the callback should be called?
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Apr 24 04:01:30 2024 UTC