config.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. <?php
  2. use Imi\App;
  3. $mode = App::isInited() ? App::getApp()->getType() : '';
  4. $isMysql = ('mysql' === strtolower(getenv('TFB_TEST_DATABASE') ?: 'mysql'));
  5. $host = 'tfb-database';
  6. $username = 'benchmarkdbuser';
  7. $password = 'benchmarkdbpass';
  8. return [
  9. // 项目根命名空间
  10. 'namespace' => 'ImiApp',
  11. // 配置文件
  12. 'configs' => [
  13. 'beans' => __DIR__ . '/beans.php',
  14. ],
  15. // 组件命名空间
  16. 'components' => [],
  17. // 主服务器配置
  18. 'mainServer' => 'swoole' === $mode ? [
  19. 'namespace' => 'ImiApp\ApiServer',
  20. 'type' => Imi\Swoole\Server\Type::HTTP,
  21. 'host' => '0.0.0.0',
  22. 'port' => 8080,
  23. 'mode' => SWOOLE_BASE,
  24. 'configs' => [
  25. 'worker_num' => swoole_cpu_num(),
  26. 'open_tcp_nodelay' => true,
  27. 'tcp_fastopen' => true,
  28. 'http_parse_post' => false,
  29. 'http_parse_cookie' => false,
  30. 'http_parse_files' => false,
  31. 'http_compression' => false,
  32. ],
  33. ] : [],
  34. // Workerman 服务器配置
  35. 'workermanServer' => 'workerman' === $mode ? [
  36. // 服务器名,http 也可以改成 abc 等等,完全自定义
  37. 'http' => [
  38. // 指定服务器命名空间
  39. 'namespace' => 'ImiApp\ApiServer',
  40. // 服务器类型
  41. 'type' => Imi\Workerman\Server\Type::HTTP, // HTTP、WEBSOCKET、TCP、UDP
  42. 'host' => '0.0.0.0',
  43. 'port' => 8080,
  44. // socket的上下文选项,参考:http://doc3.workerman.net/315128
  45. 'context' => [],
  46. 'configs' => [
  47. // 支持设置 Workerman 参数
  48. 'count' => (int) shell_exec('nproc') * 4,
  49. ],
  50. ],
  51. ] : [],
  52. 'db' => [
  53. 'defaultPool' => $isMysql ? 'mysql' : 'pgsql', // 默认连接池
  54. 'connections' => [
  55. 'mysql' => [
  56. 'host' => $host,
  57. 'username' => $username,
  58. 'password' => $password,
  59. 'database' => 'hello_world',
  60. 'dbClass' => \Imi\Db\Mysql\Drivers\Mysqli\Driver::class,
  61. ],
  62. 'pgsql' => [
  63. 'host' => $host,
  64. 'username' => $username,
  65. 'password' => $password,
  66. 'database' => 'hello_world',
  67. 'dbClass' => \Imi\Pgsql\Db\Drivers\PdoPgsql\Driver::class,
  68. ],
  69. ],
  70. ],
  71. 'pools' => 'swoole' === $mode ? [
  72. // 连接池名称
  73. 'mysql' => [
  74. 'pool' => [
  75. 'class' => \Imi\Swoole\Db\Pool\CoroutineDbPool::class,
  76. 'config' => [
  77. // 池子中最多资源数
  78. 'maxResources' => intval(1024 / swoole_cpu_num()),
  79. // 池子中最少资源数
  80. 'minResources' => $isMysql ? 16 : 0,
  81. 'gcInterval' => 0,
  82. 'checkStateWhenGetResource' => false,
  83. 'requestResourceCheckInterval' => 0,
  84. ],
  85. ],
  86. // resource也可以定义多个连接
  87. 'resource' => [
  88. 'host' => $host,
  89. 'username' => $username,
  90. 'password' => $password,
  91. 'database' => 'hello_world',
  92. 'dbClass' => \Imi\Swoole\Db\Driver\Swoole\Driver::class,
  93. ],
  94. ],
  95. 'pgsql' => [
  96. 'pool' => [
  97. 'class' => \Imi\Swoole\Db\Pool\CoroutineDbPool::class,
  98. 'config' => [
  99. // 池子中最多资源数
  100. 'maxResources' => intval(1024 / swoole_cpu_num()),
  101. // 池子中最少资源数
  102. 'minResources' => $isMysql ? 0 : 16,
  103. 'checkStateWhenGetResource' => false,
  104. 'requestResourceCheckInterval' => 0,
  105. ],
  106. ],
  107. // resource也可以定义多个连接
  108. 'resource' => [
  109. 'host' => $host,
  110. 'username' => $username,
  111. 'password' => $password,
  112. 'database' => 'hello_world',
  113. 'dbClass' => \Imi\Pgsql\Db\Drivers\Swoole\Driver::class,
  114. ],
  115. ],
  116. ] : [],
  117. ];