Swoole 1.10.0 released, adding many new features

  php, swoole

Asynchronous, Parallel and High Performance Network Communication Engine of PHPSwoolePublished1.10.0Version. Several new features have been added to this release.

Automatic DNS resolution

The new version of asynchronous client is no longer requiredswoole_async_dns_lookupThe domain name was resolved, and the bottom layer realized automatic domain name resolution.ClientIn progressconnectMethod 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 requestsPHPFunction 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.logA 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

NewstreamModules enableReactorWorkerTaskCommunication between processes is more flexible and decoupled to the greatest extent. Complex online project usagestreamMode, 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();
  • ReactorAndWorkerCommunication between, usingdispatch_mode = 7To open
  • WorkerAndTaskCommunication between, usingtask_ipc_mode = 4To open

Add Event::cycle function

User code can customize oneEventLoopThis function is called at the end of each event cycle. Easy to useGenerator + YieldOrPromiseClassSwooleThe 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

  • UpdateTable::incrAndTable::decrSigned Integers Supported
  • CompatiblePHP-7.2Version
  • RepairEvent::delFunction failed to remove standard input handle
  • RepairTaskThe in-process timer interval is less thanClientReceive timeout, causingClient::recvThe Problem of Deadlock
  • Increasessl_host_nameConfiguration item for verificationSSL/TLSHost legitimacy
  • Usedispatch_mode = 3When allWorkerPrint an error log when busy
  • Add a port iterator to traverse all connections of a listening port
  • RepairTableIn Africax86Memory Alignment Problem in Platform
  • RepairBASEIn modemax_requestInvalid configuration problem
  • RepairWebSocketThe server is on some clientspingFrame withmaskError in data packet return
  • RepairHttpClientUseHEADMethod Response Content CarryingContent-LengthThe problem of causing sticking
  • IncreaseMySQLAsynchronous client pairJSONSupport for formats

Download address