swoole.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. use app\webscoket\Manager;
  12. use Swoole\Table;
  13. use think\swoole\websocket\socketio\Parser;
  14. return [
  15. 'server' => [
  16. 'host' => env('SWOOLE_HOST', '0.0.0.0'), // 监听地址
  17. 'port' => env('SWOOLE_PORT', 8324), // 监听端口
  18. 'mode' => SWOOLE_PROCESS, // 运行模式 默认为SWOOLE_PROCESS
  19. 'sock_type' => SWOOLE_SOCK_TCP, // sock type 默认为SWOOLE_SOCK_TCP
  20. 'options' => [
  21. 'pid_file' => runtime_path() . 'swoole.pid',
  22. 'log_file' => runtime_path() . 'swoole.log',
  23. 'daemonize' => false,
  24. // Normally this value should be 1~4 times larger according to your cpu cores.
  25. 'reactor_num' => swoole_cpu_num(),
  26. 'worker_num' => swoole_cpu_num(),
  27. 'task_worker_num' => swoole_cpu_num(),
  28. 'task_enable_coroutine' => false,
  29. 'task_max_request' => 2000,
  30. 'enable_static_handler' => true,
  31. 'document_root' => root_path('public'),
  32. 'package_max_length' => 20 * 1024 * 1024,
  33. 'buffer_output_size' => 10 * 1024 * 1024,
  34. 'socket_buffer_size' => 128 * 1024 * 1024,
  35. 'max_request' => 3000,
  36. 'send_yield' => true,
  37. 'reload_async' => true,
  38. ],
  39. ],
  40. 'websocket' => [
  41. 'enable' => true,
  42. 'handler' => Manager::class,
  43. 'parser' => Parser::class,
  44. 'ping_interval' => 25000, //1000 = 1秒
  45. 'ping_timeout' => 60000, //1000 = 1秒
  46. 'room' => [
  47. 'type' => 'table',
  48. 'table' => [
  49. 'room_rows' => 4096,
  50. 'room_size' => 2048,
  51. 'client_rows' => 8192,
  52. 'client_size' => 2048,
  53. ],
  54. 'redis' => [
  55. ],
  56. ],
  57. 'listen' => [],
  58. 'subscribe' => [],
  59. ],
  60. 'rpc' => [
  61. 'server' => [
  62. 'enable' => false,
  63. 'port' => 9000,
  64. 'services' => [
  65. ],
  66. ],
  67. 'client' => [
  68. ],
  69. ],
  70. 'hot_update' => [
  71. 'enable' => env('APP_DEBUG', false),
  72. 'name' => ['*.php'],
  73. 'include' => [app_path(),root_path().'crmeb'],
  74. 'exclude' => [],
  75. ],
  76. //连接池
  77. 'pool' => [
  78. 'db' => [
  79. 'enable' => true,
  80. 'max_active' => 3,
  81. 'max_wait_time' => 5,
  82. ],
  83. 'cache' => [
  84. 'enable' => true,
  85. 'max_active' => 3,
  86. 'max_wait_time' => 5,
  87. ],
  88. ],
  89. 'coroutine' => [
  90. 'enable' => false,
  91. 'flags' => SWOOLE_HOOK_ALL,
  92. ],
  93. 'tables' => [
  94. 'user' => [
  95. 'size' => 2048,
  96. 'columns' => [
  97. ['name' => 'fd', 'type' => Table::TYPE_INT],
  98. ['name' => 'type', 'type' => Table::TYPE_INT],
  99. ['name' => 'uid', 'type' => Table::TYPE_INT]
  100. ]
  101. ]
  102. ],
  103. //每个worker里需要预加载以共用的实例
  104. 'concretes' => [],
  105. //重置器
  106. 'resetters' => [],
  107. //每次请求前需要清空的实例
  108. 'instances' => [],
  109. //每次请求前需要重新执行的服务
  110. 'services' => [],
  111. 'locks' => ['group_buying'],
  112. ];