循环发送信息的时候,出错send buffer full and drop package,是不是缓冲区满了?
$socket->onConnect = function($socket) use($byname, $act_byname, $gdpay, $yestoday, $today, $Y, $bankcode, $appname)
{
//测试用
$terminal_id = '44001555';
for($i = 1; $i <= 10000; $i++)
{
$request = $gdpay->jk_datas($terminal_id, $byname, $act_byname, $yestoday, $today, $bankcode);
if($request === TRUE)
{
continue;
}
else
{
log_message($appname, 'info', "{$today}缴款发送的数据:" . $request);
$socket->send($request);
}
}
//正式生产
/*$gdpay_key = $byname . '.bankpay.terminals.' . $yestoday;
$terminals = \Uplott\Lib\Redis::instance('local_redis')->smembers($gdpay_key);
if( ! empty($terminals))
{
log_message($appname, 'info', "{$today}要缴款的笔数:" . count($terminals) . "笔");
try
{
foreach($terminals as $terminal_id)
{
$request = $gdpay->jk_datas($terminal_id, $byname, $act_byname, $yestoday, $today, $bankcode);
if($request === TRUE)
{
continue;
}
else
{
log_message($appname, 'info', "{$today}缴款发送的数据:" . $request);
$socket->send($request);
}
}
}
catch(\Exception $e)
{
log_message($appname, 'error', $e->getMessage());
}
}*/
};
//服务器响应,接收返回结果
$socket->onMessage = function($socket, $result) use($byname, $act_byname, $gdpay, $today, $appname)
{
try
{
log_message($appname, 'info', "{$today}缴款接收的数据:" . $result);
$gdpay->save_jk_datas($result, $byname, $act_byname, $today);
}
catch(\Exception $e)
{
//这里会出现send buffer full and drop package
log_message($appname, 'error', $e->getMessage());
}
};
格式太乱了,看不清
不好意思,编辑了一下
发送10000条数据,大概出现3000-4000条 2 send buffer full and drop package 错误
一提交,空格就没了
send buffer full and drop package 就是客户端接收数据慢于服务端发送速度,导致消息堆积在服务端socket缓冲区,服务端socket缓冲区大小有限定,超过这个值就会报send buffer full and drop package
解决办法,不要给客户端狂发数据。设置下onBufferFull回调,缓冲区满的时候不要再发送数据,等待onBufferDrain时再发。
服务端socket缓冲区相关参见手册
http://doc.workerman.net/315341
http://doc.workerman.net/315342
http://doc.workerman.net/315150
http://doc.workerman.net/315151
多谢,我研究一下