# onBufferDrain
## 说明:
~~~
callback Worker::$onBufferDrain
~~~
每个连接都有一个单独的应用层发送缓冲区,缓冲区大小由`TcpConnection::$maxSendBufferSize`决定,默认值为1MB,可以手动设置更改大小,更改后会对所有连接生效。
该回调在应用层发送缓冲区数据全部发送完毕后触发。一般与onBufferFull配合使用,例如在onBufferFull时停止向对端继续send数据,在onBufferDrain恢复写入数据。
## 回调函数的参数
`$connection`
连接对象,即[TcpConnection实例](http://doc.workerman.net/tcp-connection.html),用于操作客户端连接,如[发送数据](http://doc.workerman.net/tcp-connection/send.html),[关闭连接](http://doc.workerman.net/tcp-connection/close.html)等
## 范例
~~~
$worker = new Worker('websocket://0.0.0.0:8484');
$worker->onBufferFull = function($connection)
{
echo "bufferFull and do not send again\n";
};
$worker->onBufferDrain = function($connection)
{
echo "buffer drain and continue send\n";
};
// 运行worker
Worker::runAll();
~~~
提示:除了使用匿名函数作为回调,还可以[参考这里](http://doc.workerman.net/faq/callback_methods.html)使用其它回调写法。
## 参见
onBufferFull 当连接的应用层发送缓冲区满时触发
- 序言
- 启动停止
- 简单的开发示例
- 性能测试
- 性能测试-数据库
- 通讯协议
- Coroutine类
- create
- getCid
- yield
- resume
- sleep
- wait
- getTotalNum
- isExist
- defer
- Runtime类
- Worker类
- 构造函数
- 属性
- workerId
- id
- name
- protocol
- transport
- reusePort
- backlog
- connections
- stdoutFile
- pidFile
- logFile
- user
- reloadable
- daemonize
- globalEvent
- 回调属性
- onWorkerStart
- onWorkerReload
- onConnect
- onMessage
- onClose
- onBufferFull
- onBufferDrain
- onError
- 方法
- rename
- runAll
- stopAll
- listen
- TcpConnection类
- 属性
- id
- protocol
- worker
- maxSendBufferSize
- defaultMaxSendBufferSize
- defaultMaxPackageSize
- 方法
- set
- send
- getRemoteIp
- getRemotePort
- close
- destroy
- pauseRecv
- resumeRecv
- pipe
- Timer定时器类
- add
- del
- 定时器注意事项
- Channel类
- 构造方法
- push
- pop
- length
- isEmpty()