server.php
on('connect', function ($serv, $fd) { echo "Client: Connect.\n";});// 监听数据接收事件$serv->on('receive', function ($serv, $fd, $from_id, $data) { $serv->send($fd, "Server: " . $data);});// 监听连接关闭事件$serv->on('close', function ($serv, $fd) { echo "Client: Close.\n";});// 启动服务器$serv->start();
1.执行程序,启动服务器
$ sudo /usr/local/php/bin/php server.php Client: Connect.
2. 启动成功后,netstat 查看
$ sudo netstat -ntlp | grep php tcp 0 0 127.0.0.1:9501 0.0.0.0:* LISTEN 21314/php
3. telnet连接服务器
$ telnet 127.0.0.1 9501Trying 127.0.0.1...Connected to 127.0.0.1.Escape character is '^]'.helloServer: hello
退出telnet:shift+],quit
4. 结束工作进程:kill 主进程ID
$ kill 21314
参考:https://wiki.swoole.com/wiki/