Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions packages/php-wasm/compile/php/dns_polyfill.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "php.h"
#include "php_network.h"
#include "zend_API.h"
#include "zend_constants.h"
#include "dns_polyfill.h"

#ifdef HAVE_SYS_SOCKET_H
Expand Down Expand Up @@ -271,3 +272,24 @@ PHP_FUNCTION(dns_get_mx)
RETURN_FALSE;
}
/* }}} */

/* {{{ Polyfill the constants, as PHP won't load them. */
void register_dns_polyfill_symbols(int module_number)
{
REGISTER_LONG_CONSTANT("DNS_A", PHP_DNS_A, CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("DNS_NS", PHP_DNS_NS, CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("DNS_CNAME", PHP_DNS_CNAME, CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("DNS_SOA", PHP_DNS_SOA, CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("DNS_PTR", PHP_DNS_PTR, CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("DNS_HINFO", PHP_DNS_HINFO, CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("DNS_CAA", PHP_DNS_CAA, CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("DNS_MX", PHP_DNS_MX, CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("DNS_TXT", PHP_DNS_TXT, CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("DNS_SRV", PHP_DNS_SRV, CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("DNS_NAPTR", PHP_DNS_NAPTR, CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("DNS_AAAA", PHP_DNS_AAAA, CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("DNS_A6", PHP_DNS_A6, CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("DNS_ANY", PHP_DNS_ANY, CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("DNS_ALL", PHP_DNS_ALL, CONST_PERSISTENT);
}
/* }}} */
2 changes: 2 additions & 0 deletions packages/php-wasm/compile/php/dns_polyfill.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,6 @@ ZEND_END_ARG_INFO()

PHP_FUNCTION(dns_get_mx);

void register_dns_polyfill_symbols(int module_number);

#endif // PHP_WASM_DNS_POLYFILL_H
3 changes: 3 additions & 0 deletions packages/php-wasm/compile/php/php_wasm.c
Original file line number Diff line number Diff line change
Expand Up @@ -1498,6 +1498,9 @@ int php_wasm_init()
php_wasm_sapi_module.php_ini_path_override = phpini_path_override;
}

/* Register the DNS Polyfill symbols */
register_dns_polyfill_symbols(0);

php_sapi_started = 1;
php_wasm_sapi_module.additional_functions = additional_functions;
if (php_wasm_sapi_module.startup(&php_wasm_sapi_module) == FAILURE)
Expand Down
Binary file modified packages/php-wasm/node/public/8_3_0/php_8_3.wasm
Binary file not shown.
2 changes: 1 addition & 1 deletion packages/php-wasm/node/public/php_8_3.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const dependencyFilename = __dirname + '/8_3_0/php_8_3.wasm';
export { dependencyFilename };
export const dependenciesTotalSize = 15331346;
export const dependenciesTotalSize = 15331281;
export function init(RuntimeName, PHPLoader) {
/**
* Overrides Emscripten's default ExitStatus object which gets
Expand Down
8 changes: 8 additions & 0 deletions packages/php-wasm/node/src/test/php.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,14 @@ describe.each(SupportedPHPVersions)('PHP %s', (phpVersion) => {
});
expect(result.text).toEqual('bool(false)\n');
});
it('DNS_* constants should exist', async () => {
const result = await php.run({
code: `<?php
var_dump(defined('DNS_NS'));
`,
});
expect(result.text).toEqual('bool(true)\n');
});
});

describe('popen()', () => {
Expand Down
Binary file modified packages/php-wasm/web/public/kitchen-sink/8_3_0/php_8_3.wasm
Binary file not shown.
2 changes: 1 addition & 1 deletion packages/php-wasm/web/public/kitchen-sink/php_8_3.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified packages/php-wasm/web/public/light/8_3_0/php_8_3.wasm
Binary file not shown.
2 changes: 1 addition & 1 deletion packages/php-wasm/web/public/light/php_8_3.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.