php.net |  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
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: noniazzi at profideo dot com
New email:
PHP Version: OS:

 

 [2010-08-17 08:29 UTC] noniazzi at profideo dot com
Description:
------------
When using event_base_loop with the flag EVLOOP_NONBLOCK, the callback doesn't seem to be called.

Reproduce code:
---------------
<?php

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

event_set($event, STDIN, EV_READ, "ev_read", array($event, $base));
event_base_set($event, $base);
event_add($event);
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
foo


Expected result:
----------------
foo
read: [foo]
End


Actual result:
--------------
foo
End
$ foo
foo: command not found


Patches

Pull Requests

History

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] tony2001@php.net
-Status: Open +Status: Assigned -Assigned To: +Assigned To: tony2001
 [2013-01-31 19:04 UTC] tony2001@php.net
-Status: Assigned +Status: Not a bug
 [2013-01-31 19:04 UTC] tony2001@php.net
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: Fri Oct 11 10:01:27 2024 UTC