event_add

Add an event to the set of monitored events

说明

bool event_add ( resource $event [, int $timeout = -1 ] )

event_add schedules the execution of the event when the event specified in event_set occurs or in at least the time specified by the timeout argument. If timeout was not specified, not timeout is set. The event must be already initalized by event_set and event_base_set functions. If the event already has a timeout set, it is replaced by the new one.

参数

event
Valid event resource.

timeout
Optional timeout (in microseconds).

返回值

event_add returns TRUE on success or FALSE on error.

event_base_free

Destroy event base

说明

void event_base_free ( resource $event_base )

Destroys the specified event_base and frees all the resources associated. Note that it's not possible to destroy an event base with events attached to it.

参数

event_base
Valid event base resource.

event_base_loop

Handle events

说明

int event_base_loop ( resource $event_base [, int $flags = 0 ] )

Starts event loop for the specified event base.

参数

event_base
Valid event base resource.

flags
Optional parameter, which can take any combination of EVLOOP_ONCE and EVLOOP_NONBLOCK.

返回值

event_base_loop returns 0 on success, -1 on error and 1 if no events were registered.

event_base_loopbreak

Abort event loop

说明

bool event_base_loopbreak ( resource $event_base )

Abort the active event loop immediately. The behaviour is similar to break statement.

参数

event_base
Valid event base resource.

返回值

event_base_loopbreak returns TRUE on success or FALSE on error.

event_base_loopexit

Exit loop after a time

说明

bool event_base_loopexit ( resource $event_base [, int $timeout = -1 ] )

The next event loop iteration after the given timer expires will complete normally, then exit without blocking for events again.

参数

event_base
Valid event base resource.

timeout
Optional timeout parameter (in microseconds).

返回值

event_base_loopexit returns TRUE on success or FALSE on error.

event_base_new

Create and initialize new event base

说明

resource event_base_new ( void )

Returns new event base, which can be used later in event_base_set, event_base_loop and other functions.

参数

此函数没有参数。

返回值

event_base_new returns valid event base resource on success or FALSE on error.

event_base_priority_init

Set the number of event priority levels

说明

bool event_base_priority_init ( resource $event_base , int $npriorities )

Sets the number of different event priority levels.

By default all events are scheduled with the same priority (npriorities/2). Using event_base_priority_init you can change the number of event priority levels and then set a desired priority for each event.

参数

event_base
Valid event base resource.

npriorities
The number of event priority levels.

返回值

event_base_priority_init returns TRUE on success or FALSE on error.

event_base_reinit

Reinitialize the event base after a fork

说明

bool event_base_reinit ( resource $event_base )

Some event mechanisms do not survive across fork. The event_base needs to be reinitialized with this function.

参数

event_base
Valid event base resource that needs to be re-initialized.

返回值

成功时返回 TRUE, 或者在失败时返回 FALSE

event_base_set

Associate event base with an event

说明

bool event_base_set ( resource $event , resource $event_base )

Associates the event_base with the event.

参数

event
Valid event resource.

event_base
Valid event base resource.

返回值

event_base_set returns TRUE on success or FALSE on error.

event_buffer_base_set

Associate buffered event with an event base

说明

bool event_buffer_base_set ( resource $bevent , resource $event_base )

Assign the specified bevent to the event_base.

参数

bevent
Valid buffered event resource.

event_base
Valid event base resource.

返回值

event_buffer_base_set returns TRUE on success or FALSE on error.

event_buffer_disable

Disable a buffered event

说明

bool event_buffer_disable ( resource $bevent , int $events )

Disables the specified buffered event.

参数

bevent
Valid buffered event resource.

events
Any combination of EV_READ and EV_WRITE.

返回值

event_buffer_disable returns TRUE on success or FALSE on error.

event_buffer_enable

Enable a buffered event

说明

bool event_buffer_enable ( resource $bevent , int $events )

Enables the specified buffered event.

参数

bevent
Valid buffered event resource.

events
Any combination of EV_READ and EV_WRITE.

返回值

event_buffer_enable returns TRUE on success or FALSE on error.

event_buffer_fd_set

Change a buffered event file descriptor

说明

void event_buffer_fd_set ( resource $bevent , resource $fd )

Changes the file descriptor on which the buffered event operates.

参数

bevent
Valid buffered event resource.

fd
Valid PHP stream, must be castable to file descriptor.

event_buffer_free

Destroy buffered event

说明

void event_buffer_free ( resource $bevent )

Destroys the specified buffered event and frees all the resources associated.

参数

bevent
Valid buffered event resource.

event_buffer_new

Create new buffered event

说明

resource event_buffer_new ( resource $stream , mixed $readcb , mixed $writecb , mixed $errorcb [, mixed $arg ] )

Libevent provides an abstraction layer on top of the regular event API. Using buffered event you don't need to deal with the I/O manually, instead it provides input and output buffers that get filled and drained automatically.

参数

stream
Valid PHP stream resource. Must be castable to file descriptor.

readcb
Callback to invoke where there is data to read, or NULL if no callback is desired.

writecb
Callback to invoke where the descriptor is ready for writing, or NULL if no callback is desired.

errorcb
Callback to invoke where there is an error on the descriptor, cannot be NULL.

arg
An argument that will be passed to each of the callbacks (optional).

返回值

event_buffer_new returns new buffered event resource on success or FALSE on error.

event_buffer_priority_set

Assign a priority to a buffered event

说明

bool event_buffer_priority_set ( resource $bevent , int $priority )

Assign a priority to the bevent.

参数

bevent
Valid buffered event resource.

priority
Priority level. Cannot be less than zero and cannot exceed maximum priority level of the event base (see event_base_priority_init).

返回值

event_buffer_priority_set returns TRUE on success or FALSE on error.

event_buffer_read

Read data from a buffered event

说明

string event_buffer_read ( resource $bevent , int $data_size )

Reads data from the input buffer of the buffered event.

参数

bevent
Valid buffered event resource.

data_size
Data size in bytes.

event_buffer_set_callback

Set or reset callbacks for a buffered event

说明

bool event_buffer_set_callback ( resource $event , mixed $readcb , mixed $writecb , mixed $errorcb [, mixed $arg ] )

Sets or changes existing callbacks for the buffered event.

参数

event
Valid buffered event resource.

readcb
Callback to invoke where there is data to read, or NULL if no callback is desired.

writecb
Callback to invoke where the descriptor is ready for writing, or NULL if no callback is desired.

errorcb
Callback to invoke where there is an error on the descriptor, cannot be NULL.

arg
An argument that will be passed to each of the callbacks (optional).

返回值

成功时返回 TRUE, 或者在失败时返回 FALSE

event_buffer_timeout_set

Set read and write timeouts for a buffered event

说明

void event_buffer_timeout_set ( resource $bevent , int $read_timeout , int $write_timeout )

Sets the read and write timeouts for the specified buffered event.

参数

bevent
Valid buffered event resource.

read_timeout
Read timeout (in seconds).

write_timeout
Write timeout (in seconds).

event_buffer_watermark_set

Set the watermarks for read and write events

说明

void event_buffer_watermark_set ( resource $bevent , int $events , int $lowmark , int $highmark )

Sets the watermarks for read and write events. Libevent does not invoke read callback unless there is at least lowmark bytes in the input buffer; if the read buffer is beyond the highmark, reading is stopped. On output, the write callback is invoked whenever the buffered data falls below the lowmark.

参数

bevent
Valid buffered event resource.

events
Any combination of EV_READ and EV_WRITE.

lowmark
Low watermark.

highmark
High watermark.

event_buffer_write

Write data to a buffered event

说明

bool event_buffer_write ( resource $bevent , string $data [, int $data_size = -1 ] )

Writes data to the specified buffered event. The data is appended to the output buffer and written to the descriptor when it becomes available for writing.

参数

bevent
Valid buffered event resource.

data
The data to be written.

data_size
Optional size parameter. event_buffer_write writes all the data by default.

返回值

event_buffer_write returns TRUE on success or FALSE on error.

event_del

Remove an event from the set of monitored events

说明

bool event_del ( resource $event )

Cancels the event.

参数

event
Valid event resource.

返回值

event_del returns TRUE on success or FALSE on error.

event_free

Free event resource

说明

void event_free ( resource $event )

Frees previously created event resource.

参数

event
Valid event resource.

event_new

Create new event

说明

resource event_new ( void )

Creates and returns a new event resource.

返回值

event_new returns a new event resource on success or FALSE on error.

event_priority_set

Assign a priority to an event

说明

bool event_priority_set ( resource $event , int $priority )

Assign a priority to the event.

参数

event
Valid event resource.

priority
Priority level. Cannot be less than zero and cannot exceed maximum priority level of the event base (see event_base_priority_init).

返回值

成功时返回 TRUE, 或者在失败时返回 FALSE

event_set

Prepare an event

说明

bool event_set ( resource $event , mixed $fd , int $events , mixed $callback [, mixed $arg ] )

Prepares the event to be used in event_add. The event is prepared to call the function specified by the callback on the events specified in parameter events, which is a set of the following flags: EV_TIMEOUT, EV_SIGNAL, EV_READ, EV_WRITE and EV_PERSIST.

If EV_SIGNAL bit is set in parameter events, the fd is interpreted as signal number.

After initializing the event, use event_base_set to associate the event with its event base.

In case of matching event, these three arguments are passed to the callback function:

fd
Signal number or resource indicating the stream.

events
A flag indicating the event. Consists of the following flags: EV_TIMEOUT, EV_SIGNAL, EV_READ, EV_WRITE and EV_PERSIST.

arg
Optional parameter, previously passed to event_set as arg.

参数

event
Valid event resource.

fd
Valid PHP stream resource. The stream must be castable to file descriptor, so you most likely won't be able to use any of filtered streams.

events
A set of flags indicating the desired event, can be EV_READ and/or EV_WRITE. The additional flag EV_PERSIST makes the event to persist until event_del is called, otherwise the callback is invoked only once.

callback
Callback function to be called when the matching event occurs.

arg
Optional callback parameter.

返回值

event_set returns TRUE on success or FALSE on error.

更新日志

版本说明
0.0.4EV_SIGNAL support was added.

event_timer_add

别名 event_add

说明

此函数是该函数的别名: event_add.

event_timer_del

别名 event_del

说明

此函数是该函数的别名: event_del.

event_timer_new

别名 event_new

说明

此函数是该函数的别名: event_new.

event_timer_set

Prepare a timer event

说明

bool event_timer_set ( resource $event , callable $callback [, mixed $arg ] )

Prepares the timer event to be used in event_add. The event is prepared to call the function specified by the callback when the event timeout elapses.

After initializing the event, use event_base_set to associate the event with its event base.

In case of matching event, these three arguments are passed to the callback function:

fd
Signal number or resource indicating the stream.

events
A flag indicating the event. This will always be EV_TIMEOUT for timer events.

arg
Optional parameter, previously passed to event_timer_set as arg.

参数

event
Valid event resource.

callback
Callback function to be called when the matching event occurs.

arg
Optional callback parameter.

返回值

成功时返回 TRUE, 或者在失败时返回 FALSE

目录