Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Core PHP function dns_get_record is undefined #1042

Open
wojtekn opened this issue Feb 20, 2024 · 4 comments · May be fixed by #1067
Open

Core PHP function dns_get_record is undefined #1042

wojtekn opened this issue Feb 20, 2024 · 4 comments · May be fixed by #1067
Assignees
Labels
[Feature] PHP.wasm [Type] Bug An existing feature does not function as intended
Milestone

Comments

@wojtekn
Copy link
Collaborator

wojtekn commented Feb 20, 2024

The dns_get_record() function, which is a core PHP function, is undefined in PHP-WASM. It results in throwing fatal errors when it's used in code.

Steps to reproduce:

  1. Open https://playground.wordpress.net/ and enable network access
  2. Navigate to Dashboard -> Plugins
  3. Click Add New Plugin
  4. Locate the Jetpack plugin, click Install Now
  5. When the plugin is installed, click Activate

Notice the fatal error:

Fatal error: Uncaught Error: Call to undefined function Automattic\Jetpack\Status\dns_get_record() in /wordpress/wp-content/plugins/jetpack/jetpack_vendor/automattic/jetpack-status/src/class-host.php:145
@wojtekn
Copy link
Collaborator Author

wojtekn commented Feb 20, 2024

@adamziel adamziel added [Type] Bug An existing feature does not function as intended [Feature] PHP.wasm labels Feb 20, 2024
@sejas
Copy link
Collaborator

sejas commented Feb 20, 2024

Here is a quick link to trigger the same error:
https://playground.wordpress.net/?networking=yes&plugin=jetpack&url=/wp-admin/plugins.php

@p-jackson
Copy link
Member

Looking at the PHP source for dns_get_record it looks like the function is only defined if HAVE_DNS_SEARCH_FUNC is defined.

This forum post implies that the dns_get_record() function depends on functions from libc. I suspect if those functions aren't available then HAVE_DNS_SEARCH_FUNC won't be defined.

So it may come down to what's available when PHP is being compiled to wasm. Usually there's a ./configure script which sets up constants like HAVE_DNS_SEARCH_FUNC based on which functions are available on the current system. Are all these libc functions available to the web assembly target we're compiling to?

adamziel added a commit that referenced this issue Feb 27, 2024
Closes #1042 by
polyfilling the dns_* functions that are missing in the WebAssembly
build of PHP. In the PHP source code, these functions are included
conditionally when the HAVE_DNS_SEARCH_FUNC constant is true, which it
isn't in the Emscripten build.

The polyfills return either `false` or an empty array and do not
actually perform any DNS checks.

In Node.js, we could support actual dns checks. Let's leave that for a
subsequent iteration. In the browser, there isn't much we can do.

 ## Remaining work

Rebuild the browser versions of PHP

 ## Testing instructions

Confirm the CI checks pass

CC @p-jackson @sejas @wojtekn
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] PHP.wasm [Type] Bug An existing feature does not function as intended
Projects
Status: No status
Development

Successfully merging a pull request may close this issue.

5 participants