swoole.php 3.3 KB

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