swoole.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. <?php
  2. //use think\swoole\websocket\socketio\Handler;
  3. use app\common\websocket\Handler;
  4. return [
  5. 'server' => [
  6. 'host' => env('SWOOLE_HOST', '0.0.0.0'), // 监听地址
  7. 'port' => env('SWOOLE_PORT', 30211), // 监听端口
  8. 'mode' => SWOOLE_PROCESS, // 运行模式 默认为SWOOLE_PROCESS
  9. 'sock_type' => SWOOLE_SOCK_TCP, // sock type 默认为SWOOLE_SOCK_TCP
  10. 'options' => [
  11. 'pid_file' => runtime_path() . 'swoole.pid',
  12. 'log_file' => runtime_path() . 'swoole.log',
  13. 'daemonize' => false,
  14. // Normally this value should be 1~4 times larger according to your cpu cores.
  15. 'reactor_num' => swoole_cpu_num(),
  16. 'worker_num' => swoole_cpu_num(),
  17. 'task_worker_num' => swoole_cpu_num(),
  18. 'enable_static_handler' => true,
  19. 'document_root' => root_path('public'),
  20. 'package_max_length' => 20 * 1024 * 1024,
  21. 'buffer_output_size' => 10 * 1024 * 1024,
  22. 'socket_buffer_size' => 128 * 1024 * 1024,
  23. 'heartbeat_idle_time' => 600, // 一个连接如果600秒内未向服务器发送任何数据,此连接将被强制关闭
  24. 'heartbeat_check_interval' => 60, // 每60秒遍历一次
  25. ],
  26. ],
  27. 'websocket' => [
  28. 'enable' => true,
  29. 'handler' => Handler::class,
  30. 'ping_interval' => 25000,
  31. 'ping_timeout' => 60000,
  32. 'room' => [
  33. 'type' => 'table',
  34. 'table' => [
  35. 'room_rows' => 4096,
  36. 'room_size' => 2048,
  37. 'client_rows' => 8192,
  38. 'client_size' => 2048,
  39. ],
  40. 'redis' => [
  41. 'host' => '127.0.0.1',
  42. 'port' => 6379,
  43. 'max_active' => 3,
  44. 'max_wait_time' => 5,
  45. ],
  46. ],
  47. 'listen' => [],
  48. 'subscribe' => [],
  49. ],
  50. 'rpc' => [
  51. 'server' => [
  52. 'enable' => false,
  53. 'port' => 9000,
  54. 'services' => [
  55. ],
  56. ],
  57. 'client' => [
  58. ],
  59. ],
  60. 'hot_update' => [
  61. 'enable' => env('APP_DEBUG', false),
  62. 'name' => ['*.php'],
  63. 'include' => [app_path()],
  64. 'exclude' => [],
  65. ],
  66. //连接池
  67. 'pool' => [
  68. 'db' => [
  69. 'enable' => true,
  70. 'max_active' => 3,
  71. 'max_wait_time' => 5,
  72. ],
  73. 'cache' => [
  74. 'enable' => true,
  75. 'max_active' => 3,
  76. 'max_wait_time' => 5,
  77. ],
  78. //自定义连接池
  79. ],
  80. //队列
  81. 'queue' => [
  82. 'enable' => false,
  83. 'workers' => [],
  84. ],
  85. 'coroutine' => [
  86. 'enable' => true,
  87. 'flags' => SWOOLE_HOOK_ALL,
  88. ],
  89. 'tables' => [],
  90. //每个worker里需要预加载以共用的实例
  91. 'concretes' => [],
  92. //重置器
  93. 'resetters' => [],
  94. //每次请求前需要清空的实例
  95. 'instances' => [],
  96. //每次请求前需要重新执行的服务
  97. 'services' => [],
  98. ];