略微加速

PHP官方手册 - 互联网笔记

PHP - Manual: Event callbacks

2024-04-19

Event callbacks

If a callback is registered for an event, it will be called when the event becomes active. To associate a callback with event one can pass a callable to either Event::__construct() , or Event::set() , or one of the factory methods like Event::timer() .

An event callback should match the following prototype:

callback( mixed $fd = null , int $what = ?, mixed $arg = null ): void

fd

The file descriptor, stream resource or socket associated with the event. For signal event fd is equal to the signal number.

what

Bit mask of all events triggered.

arg

User custom data.

Event::timer() expects the callback to match the following prototype:

callback( mixed $arg = null ): void

arg

User custom data.

Event::signal() expects the callback to match the following prototype:

callback( int $signum = ?, mixed $arg = null ): void

signum

The number of the triggered signal(e.g. SIGTERM ).

arg

User custom data.

add a noteadd a note

User Contributed Notes 1 note

up
0
xilon dot jul at gmail dot com
9 years ago
For event timers, the callback prototype is equivalent to sockets related callback. User arguments are given as the third parameter.

This has been tested under : Event version 1.6.1

官方地址:https://www.php.net/manual/en/event.callbacks.php

北京半月雨文化科技有限公司.版权所有 京ICP备12026184号-3