Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the new features of Swoole 1.10.0

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly shows you the "Swoole 1.10.0 new version of what are the new features", the content is easy to understand, clear, hope to help you solve your doubts, the following let the editor lead you to study and learn "what are the new features of the new version of Swoole 1.10.0" this article.

Automatic DNS parsing

The new version of asynchronous client no longer needs to use swoole_async_dns_lookup to resolve domain names, and the underlying layer implements automatic domain name resolution. Client can pass in the domain name directly 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\ r\ n\ n");}); $client- > on ("receive", function (swoole_client $cli, $data) {echo "Receive: $data"; $cli- > send (str_repeat ('Aids, 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 $client- > connect ('www.baidu.com', 9501)

Slow request log

The new version adds the ability to track slow requests and record the PHP function call stack for slow requests.

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 the slow request is processed, a line of error message is printed in the / tmp/trace.log 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 between Reactor, Worker and Task processes more flexible and decoupled to the maximum extent. Complex online projects use stream mode, which makes request allocation and scheduling more efficient.

Serv = new swoole_server ("127.0.0.1", 9501); $serv- > set ('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 ()

The communication between Reactor and Worker is enabled with dispatch_mode = 7.

The communication between Worker and Task is enabled with task_ipc_mode = 4.

Add Event::cycle function

User code can customize a hook function for EventLoop, which is called at the end of each round of event loops. It is convenient to use Generator + Yield or Promise-like 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 to support signed integers

Compatible with PHP-7.2 version

Fixed an issue where the Event::del function could not remove the standard input handle

Fixed a problem where the Task intra-process timer interval is less than the Client receive timeout, causing Client::recv deadlock

Added ssl_host_name configuration item to verify the validity of SSL/TLS hosts

Using dispatch_mode = 3, print an error log when all Worker is busy

Added a port iterator to traverse all connections to a listening port

Fixed the memory alignment problem of Table on non-x86 platform

Fixed invalid max_request configuration in BASE mode

Fixed a problem where the WebSocket server returned packets in some client ping frames with mask data

Fixed jam caused by HttpClient using HEAD method to respond to content carrying Content-Length

Add support for JSON format for MySQL asynchronous clients

Download address

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

These are all the contents of the article "what are the new features of Swoole 1.10.0?" Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report