Home >PHP Framework >Swoole >What does swoole on mean?
Server->on
Register the event callback function of Server. (Recommended learning: swoole video tutorial)
bool Server->on(string $event, mixed $callback);
The first parameter is the name of the callback, which is not case-sensitive. For specific content, please refer to the callback function list. The event name string is not required The second function added on
is the callback PHP function, which can be a string of function names, class static methods, object method arrays, and anonymous functions.
When the on method is called repeatedly, the last setting will be overwritten
$serv = new Swoole\Server("127.0.0.1", 9501); $serv->on('connect', function ($serv, $fd){ echo "Client:Connect.\n"; }); $serv->on('receive', function ($serv, $fd, $reactor_id, $data) { $serv->send($fd, 'Swoole: '.$data); $serv->close($fd); }); $serv->on('close', function ($serv, $fd) { echo "Client: Close.\n"; }); $serv->start();
The above is the detailed content of What does swoole on mean?. For more information, please follow other related articles on the PHP Chinese website!