The new version of Swoole 1.10.0 is released, with multiple new features added.
Preface
Swoole can be widely used in the Internet, mobile communication, enterprise software, cloud computing, online games, IOT, IOV, Smart Home, and other fields. Using PHP + Swoole as the network communication framework can greatly improve the efficiency of enterprise it r & D teams and focus more on developing innovative products. Recently, PHP's asynchronous, parallel, and high-performance network communication engine Swoole has released version 1.10.0. This version adds many new features. I won't talk much about it below. Let's take a look at the detailed introduction.
Automatic DNS resolution
The new asynchronous client does not need to use swoole_async_dns_lookup to resolve the domain name. The underlying layer implements automatic domain name resolution. The Client can directly pass in the domain name when executing the connect method.
$ 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") ;}); $ 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 ";}); // The underlying layer automatically performs asynchronous domain name resolution $ client-> connect ('www .baidu.com ', 9501 );
Slow request log
The new version adds the slow request tracking function, which records slow requests in the PHP 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, an error message is printed in the/tmp/trace. 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
New STREAM module
The new stream module makes the communication methods between Reactor, Worker, and Task processes more flexible and decoupled to the maximum extent. Complex online projects use the stream mode, which improves the efficiency of request allocation and scheduling.
$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();
- Communication between Reactor and Worker is enabled using dispatch_mode = 7.
- Communication between Worker and Task is enabled using task_ipc_mode = 4.
Added the Event: cycle Function.
The user code can customize an EventLoop hook function, which is called at the end of each event loop. It is convenient to use the Generator + Yield or Promise Swoole framework to implement your 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 and Table: decr. signed integer types are supported.
- Compatible with PHP-7.2 versions
- Fixed the problem where the Event: del function could not remove the standard input handle.
- Fixed the problem that the timer interval in the Task process is less than the Client receiving timeout time, causing the Client: recv deadlock.
- Added the ssl_host_name configuration item to verify the validity of the SSL/TLS host.
- When dispatch_mode = 3 is used, an error log is printed when all workers are busy.
- Adds a port iterator to traverse all connections on a listening port.
- Fixed the memory alignment problem of Table on non-x86 platforms.
- Fixed the problem of invalid max_request configuration in BASE mode.
- Fixed the problem that WebSocket server returned packet errors when some clients ping frames with mask data.
- Fixed the issue where HttpClient uses the HEAD method to respond to Content-Length leading to stuck Content.
- Added support for MySQL asynchronous clients in JSON format.
GITHUB: https://github.com/swoole/swoole-src/releases/tag/v1.10.0
Open source China: https://gitee.com/swoole/swoole/tree/v1.10.0/
PECL: https://pecl.php.net/package/swoole/1.10.0
Http://xiazai.jb51.net/201801/yuanma/swoole-src-1.10.0 (jb51.net).rar
Summary
The above is all the content of this article. I hope the content of this article has some reference and learning value for everyone's learning or work. If you have any questions, please leave a message to us, thank you for your support.