(PECL event >= 1.2.6-beta)
EventListener::__construct — Creates new connection listener associated with an event base
$base
,$cb
,$data
,$flags
,$backlog
,$target
Creates new connection listener associated with an event base.
base
Associated event base.
cb
A callable that will be invoked when new connection received.
data
Custom user data attached to cb
.
flags
Bit mask of EventListener::OPT_*
constants. See EventListener constants .
backlog
Controls the maximum number of pending connections that the network stack should allow to wait in a not-yet-accepted state at any time; see documentation for your system’s listen
function for more details. If backlog
is negative, Libevent tries to pick a good value for the backlog
; if it is zero, Event assumes that listen
is already called on the socket (target
).
target
May be string, socket resource, or a stream associated with a socket. In case if target
is a string, the string will be parsed as network address. It will be interpreted as a UNIX domain socket path, if prefixed with 'unix:'
, e.g. 'unix:/tmp/my.sock'
.
Version | Description |
---|---|
PECL event 1.5.0 | UNIX domain sockets' support added. |
Example #1 EventListener::__construct() example
<?php
class MyListenerConnection {
private $bev, $base;
public function __destruct() {
$this->bev->free();
}
public function __construct($base, $fd) {
$this->base = $base;
$this->bev = new EventBufferEvent($base, $fd, EventBufferEvent::OPT_CLOSE_ON_FREE);
$this->bev->setCallbacks(array($this, "echoReadCallback"), NULL,
array($this, "echoEventCallback"), NULL);
if (!$this->bev->enable(Event::READ)) {
echo "Failed to enable READ\n";
return;
}
}
public function echoReadCallback($bev, $ctx) {
// Copy all the data from the input buffer to the output buffer