PHP code example of flxxyz / swoole-websocket-and-tcp-and-udp
1. Go to this page and download the library: Download flxxyz/swoole-websocket-and-tcp-and-udp library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
flxxyz / swoole-websocket-and-tcp-and-udp example snippets
$config = [
'timezone' => 'Asia/Shanghai',
'tick_interval_timer' => 30, //秒
'websocket' => [
'enable' => true,
'host' => '0.0.0.0',
'port' => '9000',
'type' => SWOOLE_SOCK_TCP,
'setting' => [
'daemonize' => false,
'task_worker_num' => 1,
],
'handler' => \swoole_websocket_and_tcp_and_udp_test\webscoket::class,
],
'http' => [
'enable' => true,
'host' => '0.0.0.0',
'port' => '9001',
'type' => SWOOLE_SOCK_TCP,
'setting' => [],
'handler' => \swoole_websocket_and_tcp_and_udp_test\http::class,
],
'tcp' => [
'enable' => true,
'host' => '0.0.0.0',
'port' => '9002',
'type' => SWOOLE_SOCK_TCP,
'setting' => [
'open_eof_check' => true,
'package_eof' => "\r\n",
'dispatch_mode' => 2,
'heartbeat_check_interval' => 30,
'heartbeat_idle_time' => 60,
],
'handler' => \swoole_websocket_and_tcp_and_udp_test\tcp::class,
],
'udp' => [
'enable' => true,
'host' => '0.0.0.0',
'port' => '9003',
'type' => SWOOLE_SOCK_UDP,
'setting' => [
'open_eof_check' => true,
'package_eof' => "\r\n",
],
'handler' => '',
],
];
$server = new \swoole_websocket_and_tcp_and_udp\Server($config);
$server->run();