// This callback is invoked when there is data to read on $bevpublic function acceptConnCallback($listener, $fd, $address, $ctx) {// We got a new connection! Set up a bufferevent for it. */$base = $this->base;$this->conn[] = new MyListenerConnection($base, $fd); }

// This callback is invoked when a client accepts new connectionfunction ssl_accept_cb($listener, $fd, $address, $ctx) {// We got a new connection! Set up a bufferevent for it.$this->bev = EventBufferEvent::sslSocket($this->base, $fd, $this->ctx,EventBufferEvent::SSL_ACCEPTING, EventBufferEvent::OPT_CLOSE_ON_FREE);

// This callback is invoked when we failed to setup new connection for a clientfunction accept_error_cb($listener, $ctx) {fprintf(STDERR, "Got an error %d (%s) on the listener. "."Shutting down.\n",EventUtil::getLastSocketErrno(),EventUtil::getLastSocketError());

// This callback is invoked when there is data to read on $bevpublic function acceptConnCallback($listener, $fd, $address, $ctx) {// We got a new connection! Set up a bufferevent for it. */$base = $this->base;$this->conn[] = new MyListenerConnection($base, $fd); }

User Contributed Notes 1 note

In order to use certain features used in the examples above here you need a very recent version of libevent (>= 2.1).Although 'pecl install event' will not show any errors, certain features are disabled and certain function calls might use a different number of parameters.For example EventHttp will throw a warning that the number of parameters should be 1 instead of 2 (when using it with a SSL context) and as a bonus cause a segmentation fault.

On some distributions of Linux, the stable libevent library might not be recent enough for all features to be enabled and you might need to use an alpha version.

You can install an alpha version of libevent next to the stable version that might already be on your machine.The basic steps are:- download the alpha tarball to a folder e.g libevent-2.1.3-alpha.tar.gz- tar zxvf libevent-2.1.3-alpha.tar.gz- cd libevent-2.1.3-alpha- ./configure --prefix=/opt/libevent-alpha- make- make install

Now the alpha version of libevent is created in /opt/libevent-alpha.

Before running pecl, first export the library folder of libevent so that pecl knows where your most recent libevent stuff is:export LD_LIBRARY_PATH=/opt/libevent-2.1.3-alpha/libWithout this export I couldn't get pecl to use the correct libevent

Now run 'pecl install event'and when asked libevent installation prefix [/usr] : enter : /opt/libevent-2.1.3-alphaNow pecl will use your alpha version of libevent instead of the default version.

If everything goes well then you should be able to enjoy the full glory of this wonderfull extension.

If you try to install a very recent version of libevent on a system with a old version of openssl (0.9), you also need to update that because there are some dependencies in libevent that do not work with 0.9