v4.6.7 版本主要是一个 Bug 修复版本,没有向下不兼容改动。php
此版本中修复了Http\Response::end()
方法老是返回 true
的问题,同时修改了 output_buffer_size
的默认值git
在以前的版本中 output_buffer_size
的默认值为2M
,因为受到 output_buffer_size
的限制,若是在调用end
时,须要发送的内容大于这个限制则会响应失败,并抛出以下错误:github
use Swoole\Http\Server; use Swoole\Http\Request; use Swoole\Http\Response; $http = new Server('127.0.0.1', 9501); $http->set([ 'http_compression' => false, 'buffer_output_size' => 128 * 1024, ]); $http->on('request', function (Request $request, Response $response) { assert($response->end(str_repeat('A', 256 * 1024)) === false); assert(swoole_last_error() === SWOOLE_ERROR_DATA_LENGTH_TOO_LARGE); }); $http->start();
使用以上代码便可复现该错误
WARNING finish (ERRNO 1203): The length of data [262144] exceeds the output buffer size[131072], please use the sendfile, chunked transfer mode or adjust the output_buffer_size
之前的解决方法为:使用 sendfile
、write
或调整 output_buffer_size
,而此版本中将output_buffer_size
的默认值提升到了无符号 INT 最大值(UINT_MAX
)bash
从 4.5 版本开始去掉了 Worker 进程共享内存的使用,改成了所有使用 UnixSocket
管道,因此再也不须要预先分配内存。output_buffer_size
参数只是一个限制,设置为比较大的参数也不会致使额外占用内存。swoole
同时还修复了end
的返回值一直是true
的问题,以上代码中产生错误后未成功响应,返回值为false
curl
下面是完整的更新日志:函数
Process::signal()
函数 (#4190) (@matyhtf)Http\Response::end()
方法老是返回 true 的问题 (swoole/swoole-src@66fcc35) (@matyhtf)