Skip to content

Fix port conflicts when running multiple NativePHP apps on Windows #244

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

gwleuverink
Copy link
Contributor

Multiple NativePHP applications cannot run simultaneously on Windows due to port binding conflicts. The second app fails with exit code 4294967294 (EADDRINUSE) and net::ERR_NAME_NOT_RESOLVED errors.

See issue NativePHP/laravel#651

getPort sometimes reports ports as available when they're actually bound by another process. This happens due to Windows-specific port detection issues, including TIME_WAIT states and reserved port ranges that get-port doesn't properly detect.

Proposed fix

Enhanced getPhpPort() to validate that suggested ports are actually bindable:

  1. Fast path: Try get-port first (works in 99% of cases)
  2. Validation: Test binding to the suggested port with a real TCP server
  3. Smart fallback: If validation fails, incrementally search from suggestedPort + 1 upward

@gwleuverink gwleuverink self-assigned this Aug 6, 2025
@gwleuverink gwleuverink added the bug Something isn't working label Aug 6, 2025
@gwleuverink
Copy link
Contributor Author

@NativePHP/contributors What do you guys think about this?

It's not the most elegant approach, but I think it's pretty solid & will handle the 1% scenario where getPort isn't working as expected

@gwleuverink gwleuverink marked this pull request as ready for review August 7, 2025 13:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants