The v4.6.2 version is mainly a bug fix version without downward incompatible changes.
Added Coroutine\Socket->recvLine()
and Coroutine\Socket->readWithBuffer()
method
They are used to solve socket_read compatibility issues and recv(1)
a large number of system call issues when using byte-by-byte reception.
At the same time, the Response\create()
method is enhanced , which can be used independently of Server, such as:
use Swoole\Coroutine\Server;
use Swoole\Coroutine\Server\Connection;
use Swoole\Http\Request;
use Swoole\Http\Response;
Swoole\Coroutine\run(function () {
$server = new Server('0.0.0.0', 9501, false);
go(function () use ($server) {
$server->handle(function (Connection $conn) use ($server) {
$req = Request::create();
while(true) {
$data = $conn->recv();
if (strlen($data) != $req->parse($data) or $req->isCompleted()) {
break;
}
}
var_dump($req->get);
$resp = Response::create([$conn->exportSocket(), $req]);
$resp->header('X-Server', 'swoole');
$resp->end('Hello, Swoole');
$server->shutdown();
});
$server->start();
});
});
Use curl to initiate a request after startup
$ curl -I http://127.0.0.1:9501/\?hello\=swoole
HTTP/1.1 200 OK
X-Server: swoole
Server: swoole-http-server
Connection: keep-alive
Content-Type: text/html
Date: Mon, 25 Jan 2021 10:58:31 GMT
Content-Length: 13
$ curl http://127.0.0.1:9501/\?hello\=swoole
Hello, Swoole
The terminal will print the GET parameters in the request
array(1) {
["hello"]=>
string(6) "swoole"
}
The following is the complete update log:
New API
- New
Http\Request\getMethod()
method (#3987) (@luolaifa000) - New
Coroutine\Socket->recvLine()
method (#4014) (@matyhtf) - New
Coroutine\Socket->readWithBuffer()
method (#4017) (@matyhtf)
Enhance
- Enhanced
Response\create()
method, can be used independently of Server (#3998) (@matyhtf) - Support
Coroutine\Redis->hExists
returning bool type after setting compatibility_mode (swoole/swoole-src@b8cce7c) (@matyhtf) - Support
socket_read
setting PHP_NORMAL_READ option (swoole/swoole-src@b1a0dcc) (@matyhtf)
repair
- Fix
Coroutine::defer
the coredump problem under PHP8 (#3997) (@huanghantao) - Fix
Coroutine\Socket::errCode
the problem of incorrect settings when using thread context (swoole/swoole-src@004d08a) (@matyhtf) - Fix the problem that Swoole compilation fails under the latest macos (#4007) (@matyhtf)
- Fix the problem that the php stream context is a null pointer when the md5_file parameter is passed to the url (#4016) (@ZhiyangLeeCN)
Kernel
- Use AIO thread pool to hook stdio (Solve the problem of multi-coroutine read and write caused by treating stdio as socket before) (#4002) (@matyhtf)
- Refactor HttpContext (#3998) (@matyhtf)
- Refactoring
Process::wait()
(#4019) (@matyhtf)