Thanks to visit codestin.com
Credit goes to github.com

Skip to content

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
Copy link
Member

@SRWieZ SRWieZ left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm ok with the current proposition. We can improve later.

@gwleuverink gwleuverink merged commit ed09419 into main Aug 18, 2025
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.

3 participants