Home > PHP Framework > Swoole > body text

What does swoole on mean?

(*-*)浩
Release: 2019-12-12 11:17:48
Original
2215 people have browsed it

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);
Copy after login

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();
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template