Skip to content

Fix native:jump hang on Windows and harden port detection#126

Merged
simonhamp merged 1 commit into
mainfrom
jump-dynamic-port
May 12, 2026
Merged

Fix native:jump hang on Windows and harden port detection#126
simonhamp merged 1 commit into
mainfrom
jump-dynamic-port

Conversation

@simonhamp
Copy link
Copy Markdown
Member

Summary

Fixes a report from a Windows user that php artisan native:jump got stuck after printing the Laravel server line, never rendering the QR code.

Three related fixes in src/Commands/JumpCommand.php:

  • Drop the killExistingServers cleanup step. With reliable dynamic port selection in place, we don't need to hunt and kill prior processes — and the cleanup never reliably caught stray artisan serve instances anyway. Also removes the noisy "Cleaning up N existing server(s)" line.

  • Harden isPortInUse() with a bind-test alongside the existing connect-test. fsockopen only detects ports that are accepting connections; it misses ports held but not listening (stuck/half-dead Windows servers, TIME_WAIT, bound-but-not-listening). That's why a stale previous artisan serve on 8000 could fool the old check into selecting 8000 again. We now also try stream_socket_server and treat a bind failure as in-use.

  • Fix the actual Windows hang in startBridgeServer(). The bridge spawn used a trailing & to background the websocket server, which is Unix shell syntax. On Windows, & is a command separator — not a background operator — so exec() blocked forever on the long-lived bridge server, which is why the QR code never appeared. Windows now uses start "" /B ... >> log 2>&1 via popen/pclose for a proper detached spawn; Unix path is unchanged.

Test plan

  • On macOS/Linux: php artisan native:jump still starts, picks ports, shows QR, and the bridge log fills as the phone connects.
  • On Windows: php artisan native:jump reaches the QR display without hanging, even when a prior artisan serve is still running on 8000.
  • Re-run php artisan native:jump repeatedly without manually killing prior servers — each run picks fresh ports and starts cleanly.

🤖 Generated with Claude Code

- Drop killExistingServers cleanup step; rely on dynamic port selection
  so stale prior servers don't block a fresh run.
- Strengthen isPortInUse() with a bind-test alongside the connect-test
  so ports held but not accepting (stuck Windows servers, TIME_WAIT)
  aren't mistaken for free.
- Fix startBridgeServer() on Windows: the trailing `&` is a command
  separator there, not a background operator, so exec() blocked forever
  on the long-lived bridge server and the QR never rendered. Use
  `start "" /B ... >> log 2>&1` via popen/pclose to detach properly.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@simonhamp simonhamp mentioned this pull request May 11, 2026
@ZeoNish
Copy link
Copy Markdown

ZeoNish commented May 12, 2026

Win 10 pro x64
nativephp 3.3.4 (and 3.3.3, 3.3.2 ...)

image this console not close

next start more new console ConEmu
image

start qr

but console phpstorm
image

qr to console

@ZeoNish
Copy link
Copy Markdown

ZeoNish commented May 12, 2026

The patch solves the problem

image

@ZeoNish
Copy link
Copy Markdown

ZeoNish commented May 12, 2026

wow. delete "nativephp/mobile" composer and reinstall
image

solves the problem too O_O ... wtf...

@mustafa-online
Copy link
Copy Markdown

This fixed the QR problem 🥇
It's now showing on Terminal / Windows 11

@simonhamp simonhamp marked this pull request as ready for review May 12, 2026 10:18
@simonhamp simonhamp merged commit af4f72b into main May 12, 2026
4 of 5 checks passed
@simonhamp simonhamp deleted the jump-dynamic-port branch May 12, 2026 14:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants