config.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <?php
  2. $dbResourceConfig = [
  3. 'host' => 'tfb-database',
  4. 'username' => 'benchmarkdbuser',
  5. 'password' => 'benchmarkdbpass',
  6. 'database' => 'hello_world',
  7. 'dbClass' => \Imi\Db\Drivers\Swoole\Driver::class,
  8. ];
  9. return [
  10. // 项目根命名空间
  11. 'namespace' => 'ImiApp',
  12. // 配置文件
  13. 'configs' => [
  14. 'beans' => __DIR__ . '/beans.php',
  15. ],
  16. // 扫描目录
  17. 'beanScan' => [
  18. 'ImiApp\Listener',
  19. ],
  20. // 组件命名空间
  21. 'components' => [],
  22. // 主服务器配置
  23. 'mainServer' => [
  24. 'namespace' => 'ImiApp\ApiServer',
  25. 'type' => Imi\Server\Type::HTTP,
  26. 'host' => '0.0.0.0',
  27. 'port' => 8080,
  28. 'mode' => SWOOLE_BASE,
  29. 'configs' => [
  30. 'worker_num' => swoole_cpu_num(),
  31. 'open_tcp_nodelay' => true,
  32. 'tcp_fastopen' => true,
  33. 'http_parse_post' => false,
  34. 'http_parse_cookie' => false,
  35. 'http_parse_files' => false,
  36. 'http_compression' => false,
  37. ],
  38. ],
  39. 'db' => [
  40. 'defaultPool' => 'db', // 默认连接池
  41. ],
  42. 'redis' => [
  43. 'defaultPool' => 'redis', // 默认连接池
  44. 'quickFromRequestContext' => true, // 从当前上下文中获取公用连接
  45. ],
  46. 'pools' => [
  47. // 连接池名称
  48. 'db' => [
  49. // 异步池子,worker进程使用
  50. 'async' => [
  51. 'pool' => [
  52. 'class' => \Imi\Db\Pool\CoroutineDbPool::class,
  53. 'config' => [
  54. // 池子中最多资源数
  55. 'maxResources' => 512,
  56. // 池子中最少资源数
  57. 'minResources' => 16,
  58. 'gcInterval' => null,
  59. 'checkStateWhenGetResource' => false,
  60. 'requestResourceCheckInterval' => 30,
  61. ],
  62. ],
  63. // resource也可以定义多个连接
  64. 'resource' => $dbResourceConfig,
  65. ],
  66. ],
  67. 'redis' => [
  68. 'pool' => [
  69. // 协程池类名
  70. 'asyncClass' => \Imi\Redis\CoroutineRedisPool::class,
  71. 'config' => [
  72. // 池子中最多资源数
  73. 'maxResources' => 512,
  74. // 池子中最少资源数
  75. 'minResources' => 0,
  76. 'gcInterval' => null,
  77. 'checkStateWhenGetResource' => false,
  78. 'requestResourceCheckInterval' => 30,
  79. ],
  80. ],
  81. // 数组资源配置
  82. 'resource' => [
  83. 'host' => '127.0.0.1',
  84. 'port' => 6379,
  85. // 是否自动序列化变量
  86. 'serialize' => true,
  87. // 密码
  88. 'password' => null,
  89. // 第几个库
  90. 'db' => 0,
  91. ],
  92. ],
  93. ],
  94. ];