循环发送信息的时候,出错send buffer full and drop package

h8h8

循环发送信息的时候,出错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());
        }                                                    
    };
6531 5 0
5个回答

walkor 打赏

格式太乱了,看不清

  • 暂无评论
h8h8

不好意思,编辑了一下

$socket->onConnect = function($socket) use($byname)
{
    //测试用
    $terminal_id = '44001555';
    for($i = 1; $i <= 10000; $i++)
    {
        $request = $gdpay->jk_datas($terminal_id, $byname);
        if($request === TRUE)
        {
            continue;
        }
       else
       {
           log_message('info', "缴款发送的数据:" . $request);
          $socket->send($request);
       }
}

//服务器响应,接收返回结果
$socket->onMessage = function($socket, $result) use($byname)
{
    try
    {
        log_message('info', "缴款接收的数据:" . $result);
        $gdpay->save_jk_datas($result, $byname);
     }
    catch(\Exception $e)
    {        
        log_message( 'error', $e->getMessage());
    }
};

$socket->onError = function($socket, $err_code, $err_msg) use($appname)
{
        //这里会出现send buffer full and drop package
        log_message( 'error', "$err_code, $err_msg");        
};

发送10000条数据,大概出现3000-4000条 2 send buffer full and drop package 错误

  • 暂无评论
h8h8

一提交,空格就没了

  • 暂无评论
walkor 打赏

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

  • 暂无评论
h8h8

多谢,我研究一下

  • 暂无评论
年代过于久远,无法发表回答
×
🔝