Skip to content

Conversation

@adamziel
Copy link
Collaborator

@adamziel adamziel commented Dec 1, 2023

What is this PR doing?

Explores support for dynamic loading of PHP extensions.

Supersedes #673, consult that PR for the progress history and helpful comments.

Related to #314, #655, #89

Minimal dlopen example without PHP involved.

Testing instructions

Clone this branch to a directory with path /Users/cloudnik/www/Automattic/core/plugins/playground-2/wordpress-playground. It's not great, I know. I want to remove the explicit path dependency soon.

Then, create a /usr/local/etc/php.ini file with the following contents:

allow_url_fopen=1
extension=/Users/cloudnik/www/Automattic/core/plugins/playground-2/wordpress-playground/packages/php-wasm/node/public/mbstring.so
zend_extension=/Users/cloudnik/www/Automattic/core/plugins/playground-2/wordpress-playground/.libs/xdebug.so
xdebug.mode=debug
sys_temp_dir=/tmp

Finally, run:

$ nx reset; PHP=8.2 nx start php-wasm-cli -z ./.libs/xdebug.so ./test.php

Here's what you should see:

CleanShot 2023-12-01 at 12 44 58@2x

Remaining work

  • Reconcile this branch with trunk. This PR ships many stale files.
  • Clean up the code
  • Make this work with any disk path, not just the one listed above
  • Make XDebug step debugger work

@adamziel adamziel changed the title Start a fresh branch Draft: Support dynamic loading of PHP extensions via dlopen Dec 1, 2023
@adamziel
Copy link
Collaborator Author

This PR is now much simpler and xdebug functions work! However, connecting to a step debugger doesn't work yet. It seems like xdebug isn't even trying to open a remote socket here:

https://github.com/xdebug/xdebug/blob/49afefb7d9d313300369775b110c2ca2f2410b71/src/debugger/com.c#L246-L257

Xdebug: [Step Debug] Could not connect to debugging client. Tried: 127.0.0.1:9003 (through xdebug.client_host/xdebug.client_port).

@adamziel adamziel changed the title Draft: Support dynamic loading of PHP extensions via dlopen Draft: XDebug support via dlopen Dec 21, 2023
@adamziel adamziel mentioned this pull request Dec 21, 2023
@adamziel adamziel force-pushed the trunk branch 2 times, most recently from 680cd19 to 2e376d2 Compare October 4, 2024 09:24
@adamziel
Copy link
Collaborator Author

This is interesting and may enable connecting xdebug to browser devtools: https://github.com/microsoft/debug-adapter-protocol/blob/main/overview.md

There's probably already an implementation of xdebug -> debug adapter protocol built for some VS code PHP debugging extension.

@adamziel
Copy link
Collaborator Author

Superseded by #2248

@adamziel adamziel closed this Jun 23, 2025
mho22 added a commit that referenced this pull request Jul 9, 2025
…#2326)

## Motivation for the change

This is a pull request to dynamically load Xdebug in `@php-wasm` Node
ASYNCIFY.

[Roadmap](#2315)

## Related issues and pull requests

Relative to XDebug

- #2248
- #314
- #2288
- #831

Relative to dynamic library

- #89
- #2290
- #673

## Implementation details

Additional steps for asyncify are implemented : 

- new nx commands
- new `WITH_JSPI` and `WITH_DEBUG` arguments in Xdebug Dockerfile
- new `xdebug.so` files are compiled and dynamically loaded

## Zend extensions and PHP versions
> [!IMPORTANT]  
> Each version of PHP requires its own version of Xdebug because each
version of PHP has a specific Zend Engine API version. Consequently,
each version of Xdebug is designed to be compatible with a particular
Zend Engine API version.

Example using PHP `8.2` with Xdebug `8.3` :

```
Xdebug requires Zend Engine API version 420230831.
The Zend Engine API version 420220829 which is installed, is outdated.
 ```


## Testing Instructions

Two files are needed. A PHP file to test the step debugger. A JS file to run PHP 8.4 node ASYNCIFY.

`php/xdebug.php`

```php
<?php

$test = 42; // Set a breakpoint on this line

echo "Hello Xdebug World\n";
```


`scripts/node.js`

```javascript
import { PHP } from '@php-wasm/universal';
import { loadNodeRuntime } from '@php-wasm/node';


const php = new PHP( await loadNodeRuntime( '8.4', { withXdebug : true }
) );

await php.runStream( { scriptPath : `php/xdebug.php` } );
```


To achieve the test, you first need to start debugging [ with F5 or Run > Start debugging in VSCode ], then run :

```bash
node scripts/node.js
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants