env环境配置

在执行 composer install 的时候程序会自动复制环境变量配置文件。
若没有,可手动复制项目根目录的 .env.example 并命名为 .env

可用配置项

下面是官方的 .env 文件支持的env配置项, 你也可以按需添加自己需要的配置

  1. # Application
  2. TIME_ZONE=Asia/Shanghai
  3. LOG_ENABLE=false
  4. APP_DEBUG=false
  5. # Server
  6. # pid 文件,要同时在一台机器上运行多个server时,注意要更改pid文件
  7. PFILE=/tmp/swoft.pid
  8. # 项目名,要同时在一台机器上运行多个server时,注意要更改名称以方便区分
  9. PNAME=php-swoft
  10. # 是否同时启动 RPC
  11. TCPABLE=true
  12. # 是否同时启动 定时任务
  13. CRONABLE=false
  14. # 是否启用热重载。仅推荐在开发时启用
  15. AUTO_RELOAD=true
  16. AUTO_REGISTER=false
  17. # HTTP 服务器设置
  18. HTTP_HOST=0.0.0.0
  19. HTTP_PORT=80
  20. HTTP_MODE=SWOOLE_PROCESS
  21. HTTP_TYPE=SWOOLE_SOCK_TCP
  22. # WebSocket 服务器设置(它是继承自http服务器的,跟http有相同的配置项,更多请查看对应组件文档)
  23. WS_ENABLE_HTTP=true
  24. # TCP
  25. TCP_HOST=0.0.0.0
  26. TCP_PORT=8099
  27. TCP_MODE=SWOOLE_PROCESS
  28. TCP_TYPE=SWOOLE_SOCK_TCP
  29. TCP_PACKAGE_MAX_LENGTH=2048
  30. TCP_OPEN_EOF_CHECK=false
  31. # Crontab
  32. CRONTAB_TASK_COUNT=1024
  33. CRONTAB_TASK_QUEUE=2048
  34. # Swoole Settings
  35. WORKER_NUM=1
  36. MAX_REQUEST=100000
  37. DAEMONIZE=0
  38. DISPATCH_MODE=2
  39. TASK_IPC_MODE=1
  40. MESSAGE_QUEUE_KEY=1879052289
  41. TASK_TMPDIR=/tmp/
  42. LOG_FILE=@runtime/logs/swoole.log
  43. TASK_WORKER_NUM=1
  44. PACKAGE_MAX_LENGTH=2048
  45. OPEN_HTTP2_PROTOCOL=false
  46. SSL_CERT_FILE=/path/to/ssl_cert_file
  47. SSL_KEY_FILE=/path/to/ssl_key_file
  48. # Database Master nodes
  49. DB_NAME=dbMaster
  50. DB_URI=127.0.0.1:3306/test?user=root&password=123456&charset=utf8,127.0.0.1:3306/test?user=root&password=123456&charset=utf8
  51. DB_MIN_ACTIVE=5
  52. DB_MAX_ACTIVE=10
  53. DB_MAX_WAIT=20
  54. DB_MAX_WAIT_TIME=3
  55. DB_MAX_IDLE_TIME=60
  56. DB_TIMEOUT=2
  57. # Database Slave nodes
  58. DB_SLAVE_NAME=dbSlave
  59. DB_SLAVE_URI=127.0.0.1:3306/test?user=root&password=123456&charset=utf8,127.0.0.1:3306/test?user=root&password=123456&charset=utf8
  60. DB_SLAVE_MIN_ACTIVE=5
  61. DB_SLAVE_MAX_ACTIVE=10
  62. DB_SLAVE_MAX_WAIT=20
  63. DB_SLAVE_MAX_WAIT_TIME=3
  64. DB_SLAVE_MAX_IDLE_TIME=60
  65. DB_SLAVE_TIMEOUT=3
  66. # Redis
  67. REDIS_NAME=redis
  68. REDIS_DB=2
  69. REDIS_URI=127.0.0.1:6379,127.0.0.1:6379
  70. REDIS_MIN_ACTIVE=5
  71. REDIS_MAX_ACTIVE=10
  72. REDIS_MAX_WAIT=20
  73. REDIS_MAX_WAIT_TIME=3
  74. REDIS_MAX_IDLE_TIME=60
  75. REDIS_TIMEOUT=3
  76. REDIS_SERIALIZE=1
  77. # other redis node
  78. REDIS_DEMO_REDIS_DB=6
  79. REDIS_DEMO_REDIS_PREFIX=demo_redis_
  80. # User service (demo service)
  81. USER_POOL_NAME=user
  82. USER_POOL_URI=127.0.0.1:8099,127.0.0.1:8099
  83. USER_POOL_MIN_ACTIVE=5
  84. USER_POOL_MAX_ACTIVE=10
  85. USER_POOL_MAX_WAIT=20
  86. USER_POOL_TIMEOUT=200
  87. USER_POOL_MAX_WAIT_TIME=3
  88. USER_POOL_MAX_IDLE_TIME=60
  89. USER_POOL_USE_PROVIDER=false
  90. USER_POOL_BALANCER=random
  91. USER_POOL_PROVIDER=consul
  92. # User service breaker (demo service)
  93. USER_BREAKER_FAIL_COUNT = 3
  94. USER_BREAKER_SUCCESS_COUNT = 6
  95. USER_BREAKER_DELAY_TIME = 5000
  96. # Consul
  97. CONSUL_ADDRESS=http://127.0.0.1
  98. CONSUL_PORT=8500
  99. CONSUL_REGISTER_NAME=user
  100. CONSUL_REGISTER_ETO=false
  101. CONSUL_REGISTER_SERVICE_ADDRESS=127.0.0.1
  102. CONSUL_REGISTER_SERVICE_PORT=8099
  103. CONSUL_REGISTER_CHECK_NAME=user
  104. CONSUL_REGISTER_CHECK_TCP=127.0.0.1:8099
  105. CONSUL_REGISTER_CHECK_INTERVAL=10
  106. CONSUL_REGISTER_CHECK_TIMEOUT=1