Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bind serve cmd to 127.0.0.1 instead of localhost (#16937)
On latest Mac (Sierra) and perhaps earlier, `localhost` is using the ipv6 network. This creates behavior like the following: ```bash php artisan serve --port=8181 # Works curl localhost # Fails: Connection refused curl 127.0.0.1 # Works curl "http://[::1]:8181" ``` This is probably a confusing error for those hitting it when using `127.0.0.1`. We can make sure we bind to ipv4 by either binding to `0.0.0.0` or `127.0.0.1`. Binding to `127.0.0.1` is safer of course, and doesn't really change expected behavior (since ipv6 is not prevalent still and we're just talking localhost networks here). This change would behave like this: ```bash # If 127.0.0.1 is the default, we don't need to define it, # but just so you can see it in its current form: php artisan serve --host=127.0.0.1 --port=8181 # Works curl localhost # Works curl 127.0.0.1 # Fails (and anyone using this address would presumably # have a good reason for doing so, right?) curl "http://[::1]:8181" ``` Other OS considerations: 1. Windows: localhost often checks ipv6 first and then goes to ipv4 if nothings listening on v6. This creates considerable lag, so using 127.0.0.1 may work better on Windows as well 2. Linux: I don't believe this is default behavior on even newer versions of Linux, but since we're talking about localhost networks in any case, I don't see any reason not to assume ipv4 over ipv6 would be the expected localhost network to use
- Loading branch information