Asynchronous, Parallel and High Performance Network Communication Engine of PHPSwoole
Published1.10.0
Version. Several new features have been added to this release.
Automatic DNS resolution
The new version of asynchronous client is no longer requiredswoole_async_dns_lookup
The domain name was resolved, and the bottom layer realized automatic domain name resolution.Client
In progressconnect
Method can be passed directly into the domain name.
$client = new swoole_client(SWOOLE_SOCK_TCP, SWOOLE_SOCK_ASYNC);
$client->on("connect", function(swoole_client $cli) {
$cli->send("GET / HTTP/1.1\r\n\r\n");
});
$client->on("receive", function(swoole_client $cli, $data){
echo "Receive: $data";
$cli->send(str_repeat('A', 100)."\n");
sleep(1);
});
$client->on("error", function(swoole_client $cli){
echo "error\n";
});
$client->on("close", function(swoole_client $cli){
echo "Connection close\n";
});
//Asynchronous domain name resolution will be automatically performed at the bottom
$client->connect('www.baidu.com', 9501);
Slow request log
The new version adds the function of tracking slow requests, which can record slow requestsPHP
Function call stack.
function test()
{
test_sleep();
}
function test_sleep()
{
echo "sleep 5\n";
sleep(5);
}
$server = new swoole_server('127.0.0.1', 9501);
$server->set([
'worker_num' => 1,
'task_worker_num' => 1,
'trace_event_worker' => true,
'request_slowlog_timeout' => 1,
'request_slowlog_file' => '/tmp/trace.log',
]);
$server->on('Receive', function($serv, $fd, $reactor_id, $data) {
test();
$serv->send($fd, "Swoole: $data");
});
$server->start();
After processing slow requests,/tmp/trace.log
A line of error messages will be printed in the log:
[08-Jan-2018 15:21:57] [worker#0] pid 26905
[0x00007f60cda22340] sleep() /home/htf/workspace/swoole/examples/server/trace.php:10
[0x00007f60cda222e0] test_sleep() /home/htf/workspace/swoole/examples/server/trace.php:4
[0x00007f60cda22280] test() /home/htf/workspace/swoole/examples/server/trace.php:28
[0x00007f60cda22190] {closure}() /home/htf/workspace/swoole/examples/server/trace.php:42
[0x00007f60cda22140] start() /home/htf/workspace/swoole/examples/server/trace.php:42
Add STREAM module
Newstream
Modules enableReactor
、Worker
、Task
Communication between processes is more flexible and decoupled to the greatest extent. Complex online project usagestream
Mode, request allocation scheduling is more efficient.
$serv = new swoole_server("127.0.0.1", 9501);
$serv->set(array(
'dispatch_mode' => 7,
'worker_num' => 2,
));
$serv->on('receive', function (swoole_server $serv, $fd, $threadId, $data)
{
var_dump($data);
echo "#{$serv->worker_id}>> received length=" . strlen($data) . "\n";
});
$serv->start();
-
Reactor
AndWorker
Communication between, usingdispatch_mode = 7
To open -
Worker
AndTask
Communication between, usingtask_ipc_mode = 4
To open
Add Event::cycle function
User code can customize oneEventLoop
This function is called at the end of each event cycle. Easy to useGenerator + Yield
OrPromise
ClassSwoole
The framework implements its own scheduler.
Swoole\Timer::tick(2000, function ($id) {
var_dump($id);
});
Swoole\Event::cycle(function () {
echo "hello [1]\n";
Swoole\Event::cycle(function () {
echo "hello [2]\n";
Swoole\Event::cycle(null);
});
});
Other updates
- Update
Table::incr
AndTable::decr
Signed Integers Supported - Compatible
PHP-7.2
Version - Repair
Event::del
Function failed to remove standard input handle - Repair
Task
The in-process timer interval is less thanClient
Receive timeout, causingClient::recv
The Problem of Deadlock - Increase
ssl_host_name
Configuration item for verificationSSL/TLS
Host legitimacy - Use
dispatch_mode = 3
When allWorker
Print an error log when busy - Add a port iterator to traverse all connections of a listening port
- Repair
Table
In Africax86
Memory Alignment Problem in Platform - Repair
BASE
In modemax_request
Invalid configuration problem - Repair
WebSocket
The server is on some clientsping
Frame withmask
Error in data packet return - Repair
HttpClient
UseHEAD
Method Response Content CarryingContent-Length
The problem of causing sticking - Increase
MySQL
Asynchronous client pairJSON
Support for formats
Download address
- GITHUB:https://github.com/swoole/swo …
- Open source China:https://gitee.com/swoole/swoo …
- PECL:https://pecl.php.net/package/ …