Swoole\Event::set
(PECL swoole >= 1.9.0)
Modify event listener callbacks and mask
Description
Modifies the event listener callbacks and mask for the given file descriptor.
When $read_callback is not null, the readable event callback function will be modified to the specified function.
When $write_callback is not null, the writable event callback function will be updated to the specified function.
Setting SWOOLE_EVENT_READ alone disables write event listening, while setting SWOOLE_EVENT_WRITE alone disables read event listening.
Swoole\Event::set replaces callbacks but does not free them. Specifying null for callbacks (e.g., read_callback/write_callback) preserves the existing callbacks instead of clearing them.
Listening for SWOOLE_EVENT_READ without a read_callback (or SWOOLE_EVENT_WRITE without a write_callback) will cause the operation to fail and return false.
Parameters
sockFile descriptor, stream resource, sockets resource, or object.
read_callbackCallback function for readable events.
write_callbackCallback function for writable events.
flagsEvent type mask (e.g.
SWOOLE_EVENT_READ,SWOOLE_EVENT_WRITEorSWOOLE_EVENT_READ|SWOOLE_EVENT_WRITE).
Return Values
Success