Home > PHP Framework > Swoole > body text

Does swoole support multiple ports and different protocols?

(*-*)浩
Release: 2019-12-06 14:14:48
Original
2446 people have browsed it

Does swoole support multiple ports and different protocols?

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_port

The swoole_server_port object of the listening port can call the set and on methods. The usage method is exactly the same as swoole_server

The listening port can only set a few specific options, and can only set event callback functions related to data sending and receiving

The callback functions of different listening ports are still the same Worker Executed in the process space

The 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 protocol

Listen 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);
Copy after login

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',]
);
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template