Home >PHP Framework >Swoole >What does swoole on mean?

What does swoole on mean?

(*-*)浩
(*-*)浩Original
2019-12-12 11:17:482258browse

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:What is swoole frameworkNext article:What is swoole framework