<?php //创建异步tcp客户端 $client=new swoole_client(SWOOLE_SOCK_TCP,SWOOLE_SOCK_ASYNC); //注册连接成功的回调函数 $client->on(‘connect‘,function($cli){ $cli->send("hello \n"); }); //注册数据接收 $cli:服务端信息 $data:数据 $client->on(‘receive‘,function($cli,$data){ echo "data:$data"; }); //注册连接失败 $client->on(‘error‘,function($cli){ echo "失败\n"; }); //注册关闭函数 $client->on(‘close‘,function($cli){ echo "关闭\n"; }); //发起连接 $client->connect(‘192.168.10.1‘,8080,10); //php index.php //ps -ajft //查看启动进程 //service iptables stop //关闭防火墙 ?>
注:本地无法进行异步的效果演示