Failed to allocate bufferevent for socket

Issue #25 resolved
Jost Baron created an issue

Hi!

I'm trying to run this extension with PHP 7, on XUbuntu 14.04.3, and am getting the above error. Google results do not really help.

Software versions:

pecl-event 2.0.1
libevent 2.0.5/2.0.21-stable-1ubuntu1.14.04.1
PHP 7.0.4
Ubuntu 14.04.3

A minimal script to reproduce the problem:

<?php
    function readableCallback(\EventBufferEvent $eventBufferEvent) {
            // Do stuff
    }

    $stdin = fopen('php://stdin', 'r');

    $base = new \EventBase();
    $stdinReadableEvent = new \EventBufferEvent($base, $stdin, \Event::READ | \Event::PERSIST, 'readableCallback');
    $stdinReadableEvent->add();

Output from dpkg -l | grep libevent:

ii  libevent-2.0-5:amd64                       2.0.21-stable-1ubuntu1.14.04.1          amd64        Asynchronous event notification library
ii  libevent-core-2.0-5:amd64                  2.0.21-stable-1ubuntu1.14.04.1          amd64        Asynchronous event notification library (core)
ii  libevent-dev                               2.0.21-stable-1ubuntu1.14.04.1          amd64        Asynchronous event notification library (development files)
ii  libevent-extra-2.0-5:amd64                 2.0.21-stable-1ubuntu1.14.04.1          amd64        Asynchronous event notification library (extra)
ii  libevent-openssl-2.0-5:amd64               2.0.21-stable-1ubuntu1.14.04.1          amd64        Asynchronous event notification library (openssl)
ii  libevent-pthreads-2.0-5:amd64              2.0.21-stable-1ubuntu1.14.04.1          amd64        Asynchronous event notification library (pthreads)

Information from the phpinfo about event:

event
Event support   enabled
Sockets support enabled
Debug support   disabled
Extra functionality support including HTTP, DNS, and RPC    enabled
OpenSSL support     enabled
Thread safety support   disabled
Extension version   2.0.1
libevent2 headers version   2.0.21-stable

I've compiled the extension using the default process:

phpize
configure --with-php-config=[...]
make -j
make install

Comments (3)

  1. Ruslan Osmanov repo owner

    EventBufferEvent is supposed to handle network sockets represented as PHP stream, socket resource, or numeric file descriptor(based on a socket!). You probably want something like this:

    <?php
    $stdin = fopen('php://stdin', 'r');
    
    $prompt = 'Enter a string: ';
    
    $base = new \EventBase();
    
    $e = new \Event($base, $stdin, \Event::READ | \Event::PERSIST,
        function ($stream, $events) use ($base, $prompt)
        {
            if ($events & Event::READ) {
                printf('Your line: %s%s', fgets($stream), $prompt);
            } else {
                fprintf(STDERR, "!! Unhandled events: %s\n", var_export($events, true));
                $base->exit();
            }
        });
    $e->add();
    
    echo $prompt;
    $base->loop();
    

    I admit, the error message should be more specific.

  2. Log in to comment