Skip to content

Conversation

@adamziel
Copy link
Collaborator

@adamziel adamziel commented Oct 28, 2025

Motivation for the change, related issues

Adds ImageMagick PHP extension to Node.js PHP.wasm builds.

  • Supported image formats are JPG, PNG, GIF, and WEBP (WEBP on PHP >= 8.0). There's no AVIF support yet.
  • The .wasm bundles grow by ~4.39MB each on average.

As a follow-up item, we might consider shipping Imagick in the browser.

Implementation details

--with-namespace-prefix=PHPWasm_Magick_ flag used to build imagick deserves a note. When the library is built, every public MagickCore symbol is wrapped through the PrependMagickMethod macro chain. By default, this means appending a random-ish number to their name, e.g. ReadImage_48252. This makes asyncify instrumentation effectively impossible since we need to explicitly list all the final method names. Therefore, we set --with-namespace-prefix=PHPWasm_Magick_ to use a stable, well-known prefix. This results in method names such as PHPWasm_Magick_ReadImage.

Testing Instructions (or ideally a Blueprint)

CI – this PR ships new tests for Imagick.

@adamziel adamziel marked this pull request as ready for review October 30, 2025 01:10
@adamziel adamziel requested a review from a team as a code owner October 30, 2025 01:10
@adamziel
Copy link
Collaborator Author

Test failures seem unrelated. I would still like to get to the bottom of them. All imagick tests pass!

@adamziel
Copy link
Collaborator Author

Now there are some related failures again. I'm debugging.

@adamziel
Copy link
Collaborator Author

adamziel commented Nov 1, 2025

Oki, I think we're good! These are the last two failures. cURL one is a timeout, which seems like a flaky test. I don't believe the XDebug one is related in any capacity other than perhaps different alignment of memory in the new build.

   FAIL  src/test/php-dynamic-loading.spec.ts > PHP 8.3 > XDebug > communicates with default DBGP port
  RuntimeError: memory access out of bounds
   ❯ null.<anonymous> ../../../wasm:/wasm/000ee5ce:1:42298
   ❯ null.<anonymous> ../../../wasm:/wasm/000ee5ce:1:50212
   ❯ null.<anonymous> ../../../wasm:/wasm/000ee5ce:1:50187
   ❯ null.<anonymous> ../../../wasm:/wasm/000ee5ce:1:48629
   ❯ zend_observer_fcall_end_all ../../../wasm:/wasm/php.wasm-08622cda:1:7068879
   ❯ php_request_shutdown ../../../wasm:/wasm/php.wasm-08622cda:1:5753874
   ❯ wasm_sapi_request_shutdown ../../../wasm:/wasm/php.wasm-08622cda:1:7375890
   ❯ wasm_sapi_handle_request ../../../wasm:/wasm/php.wasm-08622cda:1:7376511
   ❯ ../universal/src/lib/php.ts:693:12
      691|     }
      692| 
      693|     return await this[__private__dont__use].ccall(
         |            ^
      694|      'wasm_sapi_handle_request',
      695|      NUMBER,
   ❯ runExecutionFunction ../universal/src/lib/php.ts:1035:22
  
  ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[1/2]⎯
  
   FAIL  src/test/php-networking.spec.ts > PHP 8.2 > cURL > should support multi handle requests
  Error: Test timed out in 5000ms.
  If this is a long-running test, pass a timeout value as the last argument or configure it globally with "testTimeout".
  ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[2/2]⎯

@adamziel
Copy link
Collaborator Author

adamziel commented Nov 1, 2025

I've restarted the tests and now the memory out of bounds and timeout are reversed and also related to different PHP versions:

  ⎯⎯⎯⎯⎯⎯⎯ Failed Tests 2 ⎯⎯⎯⎯⎯⎯⎯
  
   FAIL  src/test/php-dynamic-loading.spec.ts > PHP 8.2 > XDebug > communicates with default DBGP port
  Error: Test timed out in 5000ms.
  If this is a long-running test, pass a timeout value as the last argument or configure it globally with "testTimeout".
  ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[1/2]⎯
  
   FAIL  src/test/php-networking.spec.ts > PHP 8.1 > cURL > should support single handle requests
  RuntimeError: memory access out of bounds

@brandonpayton any ideas?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants