The advantages of php are not mentioned. Swole may be familiar to some people, which is also a major innovation of php.
The advantages of php are not mentioned. Swole may be familiar to some people, which is also a major innovation of php.
Next we will introduce it.
GitHub address: https://github.com/matyhtf/swoole
Official website: http://www.swoole.com
Pecl address: http://pecl.php.net/package/swoole
The swoole project released version 1.6.10 before the Spring Festival.
Kernel Update:
-
Enabled by defaultasync_mysql (the async_mysql feature is Enabled by default in version 5.4)
-
UDP send no require from_id (udp send does not contain from_id)
-
Add last_time and connect_time to tcp connection_info (link information adds attributes: connection time and last message arrival time)
-
Add tcp heartbeat mechanic (built-in tcp heartbeat detection module)
-
Rebuild data_buffer (restructured data_buffer)
Client module:
Php method change:
Configuration change:
Swoole introduction:
Swoole is a php c extension that can be used to develop PHP's high-performance, high-concurrency TCP/UDP Server. The network I/O of Swoole is based on the multi-thread epoll/kqueue event loop, which is completely asynchronous and non-blocking. The business logic part can be fully asynchronous callback execution like node. js, or run in multi-process synchronous blocking mode. This ensures that the Server can cope with high concurrency and a large number of TCP connections. It also ensures that the business code can still be simply written.
Server sample code:
Php code
$ Serv = new swoole_server ("maid", 9501 );
$ Serv-> set (array (
'Worker _ num' => 2,
));
$ Serv-> on ('connect ', function ($ serv, $ fd ){
Echo "Client: Connect. n ";
});
$ Serv-> on ('receive ', function ($ serv, $ fd, $ from_id, $ data ){
$ Serv-> send ($ fd, 'swoole: '. $ data );
$ Serv-> close ($ fd );
});
$ Serv-> on ('close', function ($ serv, $ fd ){
Echo "Client: Close. n ";
});
$ Serv-> start ();
?>
Php server. php // Run
Telnet 127.0.0.1 9501 // connect to the server
Hello (send)
Swoole: hello (receive)
Test it on your own. Very useful.