run 命令支持从 .env 读取 HOST/PORT 配置

Open Beginner friendly
#3,197 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
1/5
Estimated time
Under an hour
Newbie friendliness
88/100
Issue type
Feature
Clarity
Clearly specified
Activity status
Quiet
Tech stack
php
Domain
cli

Research direction

Start in src/think/console/command/RunServer.php and inspect how the run command reads its host and port options, then check the project's env() configuration conventions. Done means HOST and PORT from .env provide defaults, command-line options still take precedence, and the existing 0.0.0.0 and 8000 defaults remain unchanged when neither is provided.

Written by the indexing model from the issue text.

Description

enhancement

现状

php think run 的 --host 和 --port 参数只能通过命令行传入,硬编码默认值为 0.0.0.0 和 8000:
// src/think/console/command/RunServer.php
$host = $input->getOption('host');
$port = $input->getOption('port');

需求

希望在 .env 中可以配置默认值,避免每次启动都要手动传参:
[SERVER]
HOST=0.0.0.0
PORT=9000

建议改动

$host = $input->getOption('host') ?: env('server.host', '0.0.0.0');
$port = $input->getOption('port') ?: env('server.port', 8000);
改动两行,完全向后兼容,不传 env 也不传参时行为不变。命令行参数优先级最高。

Dominant language
PHP
Stars
2.8k
Forks
1k
PR merge metrics
No merged PRs in 30d

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from top-think/framework

All issues in top-think/framework

Similar issues

More PHP issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.