// create a new event object $event = new Event('custom_event', Event::READ, function() { echo 'Custom event triggered!'; }); // create a new event base object $base = new EventBase(); // register the custom event with the event base $event->setBase($base); // dispatch the custom event $event->dispatch();
// create a new event base object $base = new EventBase(); // create a new listener object $listener = new EventListener($base, function($fd, $events, $arg) { echo 'Data received on socket ' . $fd . ': ' . fread($fd, 1024); // stop listening to this socket event_del($arg); }); // set the socket to non-blocking mode stream_set_blocking($socket, false); // register the listener with the event base $listener->setBase($base); // add the listener to the event base and start listening $listener->add($socket, Event::READ | Event::PERSIST, $listener, $socket); // start the event loop $base->loop();The examples above use the Event extension provided by the PECL package library. The package name is "event" and it can be installed using the PECL command or by downloading the source code from the PECL website.