swoole.php 3.3 KB

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