-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[DX] Smarter web server commands #21040
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
The "problem" I can see is that currently, we don't have the information about which server is running on a given port. So, when a web server is running on 8000, we don't know if this is a server for the current project or from another project. I will investigate if we can "fix" that as part of my PR decoupling the web server from framework bundle. |
OK. I was thinking about the |
But then, and that's just one example, we need to store the port somewhere so that the |
Working on it :) |
What about deprecating server:start&stop and keep only server:run? Allows having some logs right into the console. |
I can imagine that auto-discovery of the next free port can cause confusion if users do not read the output carefully enough and then visit their project in the browser and do not see the expected output. What about making the new behaviour opt-in with an option like |
@xabbuh do you really think that would be a problem? The output message is super short:
Besides, don't people just click on that link to open the page in the browser? |
Is it that common to have a port conflict btw? |
It happens to me all the time. Maybe it's because I work with lots of small apps simultaneously. In my opinion, if we add an option to enable this behavior, then it's better to not implement this behavior. Remembering the name of the option and typing it would be almost the same amount of work. |
Being able to configure the default port also sounds like a good idea to me. The default value could either be |
What about replacing the current
|
@fabpot You can already pass the port as part of the address. Though I think it indeed makes sense to unify the unit and deprecate the |
See #21039 (auto not implemented yet but easier now) |
This PR was squashed before being merged into the 3.3-dev branch (closes #21039). Discussion ---------- Web server bundle | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | yes | BC breaks? | yes | Deprecations? | no | Tests pass? | yes | Fixed tickets | #21040 | License | MIT | Doc PR | n/a Moved the `server:*` commands to a new bundle. It makes them more easily discoverable and more decoupled. Discoverability is important when not using symfony/symfony. In that case, the commands are not available unless you have the symfony/process component installed. With a dedicated bundle, installing the bundle also installs the dependency, making the whole process easier. Usage is the same as the current commands for basic usage: To start a web server in the foreground: ``` bin/console server:run ``` To manage a background server: ``` bin/console server:start bin/console server:stop bin/console server:status ``` The big difference is that port is auto-determined if something is already listening on port 8000. Usage is **different** if you pass options: ``` bin/console server:start 127.0.0.1:8888 bin/console server:stop # no need to pass the address again bin/console server:status # no need to pass the address again ``` That's possible as the web server now stores its address in a pid file stored in the current directory. Commits ------- f39b327 [WebServerBundle] switched auto-run of server:start to off by default 961d1ce [WebServerBundle] fixed server:start when already running 126f4d9 [WebServerBundle] added support for port auto-detection 6f689d6 [WebServerBundle] changed the way we keep track of the web server 585d445 [WebServerBundle] tweaked command docs fa7ebc5 [WebServerBundle] moved most of the logic in a new class 951a1a2 [WebServerBundle] changed wording ac1ba77 made the router configurable via env vars 48dd2b0 removed obsolete check 132902c moved server:* command to a new bundle
Problem
When using the
server:start
command in several apps, you must provide a free port number to avoid errors like this one:Solution
If it's technically possible, I'd like the
server:start
command to look for a free port automatically. Starting from8000
, check the followingN
ports and pick the first one available.Same example as before:
$ ./bin/console server:start [OK] Web server listening on http://127.0.0.1:8000 (change to other app in other directory) $ ./bin/console server:start [OK] Web server listening on http://127.0.0.1:8024
Depending on how fast/slow is this process, we could check 10, 100 or 1,000 ports before showing the error message.
The text was updated successfully, but these errors were encountered: