Swoole-1.8.0 adds support for multi-port mixed protocols. Server can listen to multiple ports, and each port can be set with different protocol processing methods (set) and callback functions (on). SSL/TLS transport encryption can also be enabled only for specific ports. (Recommended Learning: SWOOLE Video Tutorial )
Unclicable SET method, set the monitor port of the protocol processing option, default to inherit the setting of the main server
## on method, sets the listening port of the callback function. The callback function of the main server is used by default. The object type returned by the listening port is swoole_server_portThe swoole_server_port object of the listening port can call the set and on methods. The usage method is exactly the same as swoole_serverThe listening port can only set a few specific options, and can only set event callback functions related to data sending and receivingThe callback functions of different listening ports are still the same Worker Executed in the process spaceThe main server is WebSocket or Http protocol. The newly monitored TCP port will inherit the protocol settings of the main server by default. The set method must be called separately to set the new protocol to enable the new protocolListen to the new port
$port1 = $server->listen("127.0.0.1", 9501, SWOOLE_SOCK_TCP); $port2 = $server->listen("127.0.0.1", 9502, SWOOLE_SOCK_UDP); $port3 = $server->listen("127.0.0.1", 9503, SWOOLE_SOCK_TCP | SWOOLE_SSL);
Set the network protocol
$port1->set([ 'open_length_check' => true, 'package_length_type' => 'N', 'package_length_offset' => 0, 'package_max_length' => 800000,] ); $port3->set([ 'open_eof_split' => true, 'package_eof' => "\r\n", 'ssl_cert_file' => 'ssl.cert', 'ssl_key_file' => 'ssl.key',] );
The above is the detailed content of Does swoole support multiple ports and different protocols?. For more information, please follow other related articles on the PHP Chinese website!