The Event class

(PECL event >= 1.2.6-beta)

Introduction

Event class represents and event firing on a file descriptor being ready to read from or write to; a file descriptor becoming ready to read from or write to(edge-triggered I/O only); a timeout expiring; a signal occurring; a user-triggered event.

Every event is associated with EventBase . However, event will never fire until it is added (via Event::add() ). An added event remains in pending state until the registered event occurs, thus turning it to active state. To handle events user may register a callback which is called when event becomes active. If event is configured persistent , it remains pending. If it is not persistent, it stops being pending when it's callback runs. Event::del() method deletes event, thus making it non-pending. By means of Event::add() method it could be added again.

Class synopsis

final class Event {
/* Constants */
const int ET = 32;
const int PERSIST = 16;
const int READ = 2;
const int WRITE = 4;
const int SIGNAL = 8;
const int TIMEOUT = 1;
/* Properties */
public readonly bool $pending;
/* Methods */
public add( float $timeout = ?): bool
public __construct(
     EventBase $base ,
     mixed $fd ,
     int $what ,
     callable $cb ,
     mixed $arg = NULL
)
public del(): bool
public free(): void
public static getSupportedMethods(): array
public pending( int $flags ): bool
public set(
     EventBase $base ,
     mixed $fd ,
     int $what = ?,
     callable $cb = ?,
     mixed $arg = ?
): bool
public setPriority( int $priority ): bool
public setTimer( EventBase $base , callable $cb , mixed $arg = ?): bool
public static signal(
     EventBase $base ,
     int $signum ,
     callable $cb ,
     mixed $arg = ?
): Event
public static timer( EventBase $base , callable $cb , mixed $arg = ?): Event
}

Properties

pending

Whether event is pending. See About event persistence .

Predefined Constants

Event::ET

Indicates that the event should be edge-triggered, if the underlying event base backend supports edge-triggered events. This affects the semantics of Event::READ and Event::WRITE .

Event::PERSIST

Indicates that the event is persistent. See About event persistence .

Event::READ

This flag indicates an event that becomes active when the provided file descriptor(usually a stream resource, or socket) is ready for reading.

Event::WRITE

This flag indicates an event that becomes active when the provided file descriptor(usually a stream resource, or socket) is ready for reading.

Event::SIGNAL

Used to implement signal detection. See "Constructing signal events" below.

Event::TIMEOUT

This flag indicates an event that becomes active after a timeout elapses.

The Event::TIMEOUT flag is ignored when constructing an event: one can either set a timeout when event is added , or not. It is set in the $what argument to the callback function when a timeout has occurred.

Table of Contents

Here you can write a comment


Please enter at least 10 characters.
Loading... Please wait.
* Pflichtangabe
There are no comments available yet.

PHP cURL Tutorial: Using cURL to Make HTTP Requests

cURL is a powerful PHP extension that allows you to communicate with different servers using various protocols, including HTTP, HTTPS, FTP, and more. ...

TheMax

Autor : TheMax
Category: PHP-Tutorials

Midjourney Tutorial - Instructions for beginners

There is an informative video about Midjourney, the tool for creating digital images using artificial intelligence, entitled "Midjourney tutorial in German - instructions for beginners" ...

Mike94

Autor : Mike94
Category: KI Tutorials

Basics of views in MySQL

Views in a MySQL database offer the option of creating a virtual table based on the result of an SQL query. This virtual table can be queried like a normal table without changing the underlying data. ...

admin

Autor : admin
Category: mySQL-Tutorials

Publish a tutorial

Share your knowledge with other developers worldwide

Share your knowledge with other developers worldwide

You are a professional in your field and want to share your knowledge, then sign up now and share it with our PHP community

learn more

Publish a tutorial