Client
stream
函数存在超时设置的陷阱和Bug
,一旦没处理好会导致Server
端长时间阻塞stream
函数的fread
默认最大8192
长度限制,无法支持UDP
的大包Client
支持waitall
,在有确定包长度时可一次取完,不必循环读取Client
支持UDP connect
,解决了串包问题Client
支持长连接
除了普通的同步阻塞+select
的使用方法外,Client
还支持异步非阻塞回调。
$client = new Swoole\Client(SWOOLE_SOCK_TCP, SWOOLE_SOCK_ASYNC);
$client->on("connect", function(swoole_client $cli) {
});
$client->on("receive", function(swoole_client $cli, $data){
echo "Receive: $data";
sleep(1);
});
$client->on("error", function(swoole_client $cli){
echo "error\n";
});
$client->on("close", function(swoole_client $cli){
echo "Connection close\n";
$client->connect('127.0.0.1', 9501);
异步客户端只能使用在cli
命令行环境