Skip to content

Await PHP binary extraction before starting Electron - #129

Merged
simonhamp merged 1 commit into
NativePHP:mainfrom
SRWieZ:agent/await-php-binary-extraction
Aug 25, 2026
Merged

Await PHP binary extraction before starting Electron#129
simonhamp merged 1 commit into
NativePHP:mainfrom
SRWieZ:agent/await-php-binary-extraction

Conversation

@SRWieZ

@SRWieZ SRWieZ commented Jul 18, 2026

Copy link
Copy Markdown
Member

What changed

  • wait for the bundled PHP archive to finish extracting before the Electron development process continues
  • wait for executable permissions to be applied to the extracted PHP binary
  • propagate extraction failures through a non-zero process exit code

Why

php.js previously started the callback-based yauzl extraction and returned immediately. Because the package script chains it with electron-vite dev, Electron could start while the PHP binary was still being written or before chmod completed. On Linux this produced partial binaries, permission errors, and intermittent startup failures.

Developer impact

NativePHP development startup now continues only after the bundled PHP executable is complete and runnable. Missing or unreadable archives also stop the package script instead of allowing startup to proceed with an invalid runtime.

Validation

  • npx prettier --check php.js
  • npx eslint php.js
  • node --check php.js
  • extracted DevKeepr's real 65 MB Linux PHP 8.4 archive and executed php --version immediately after the script exited
  • verified a missing archive returns exit code 1

@SRWieZ
SRWieZ marked this pull request as ready for review July 18, 2026 20:19
@sylvesterdamgaard

Copy link
Copy Markdown

This bites native:build too, not just dev — and on macOS the symptom is worse than "partial binary".

electron-builder copies the PHP binary while it's still being written. The Mach-O signature lives at the end of the file, so a truncated copy is an unsigned one, and Apple Silicon SIGKILLs it. The app launches, the window is blank, nothing is logged. Doesn't look like a packaging bug — looks like your app is broken.

Truncated, not corrupt: cmp gave a byte-identical prefix, and otool -l was cut off mid-LC_CODE_SIGNATURE.

One gotcha if anyone guards this with a size check: re-signing changes the size in both directions (ours: 68,318,496 → 67,940,352 after a legitimate re-sign), so a size comparison calls a healthy binary damaged. codesign --verify is the check that works.

Worth merging.

@simonhamp simonhamp left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nice find. Great fix

@simonhamp
simonhamp merged commit 8ba6171 into NativePHP:main Aug 25, 2026
52 checks passed
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.

4 participants