"PHP is compiled or limited to using 32-bit integers"
Running Drupal 10.3, I get the following warning
You are running on a system where PHP is compiled or limited to using 32-bit integers. This will limit the range of dates and timestamps to the years 1901-2038. Read about the limitations of 32-bit PHP.
Looks like it has nothing to do with php-wasm: https://github.com/emscripten-core/emscripten/issues/12087
But there is an experimental flag: https://github.com/emscripten-core/emscripten/pull/17708
https://emscripten.org/docs/tools_reference/settings_reference.html?highlight=memory64#memory64
-sMEMORY64
It's tied to the larger WebAssembly spec: https://github.com/WebAssembly/memory64
In Makefile we can do something like:
MEMORY64 ?=0
This way it defaults to 32bit, but someone can pass 1 for 64bit or 2 for the mix.
-s MODULARIZE=1 \
-s ASYNCIFY=1 \
-s MEMORY64=${MEMORY64} \
Announcement of support as well: https://v8.dev/features/wasm-bigint
Actually this shows Memory64 support: https://webassembly.org/features/. It looks like it's all behind feature flags.
I wonder if the -sWASM_BIGINT flag would be enough? That has wide spread support.
I tried a build with -sWASM_BIGINT and it crashed: Cannot convert 0 to a BigInt.
500: Internal Server Error.
================================================================================
Stacktrace:
TypeError: Cannot convert 0 to a BigInt
at ret.<computed> (http://localhost/php-cgi-worker.mjs:9:380235)
at wasm://wasm/0058e82e:wasm-function[1787]:0x150853
at wasm://wasm/0058e82e:wasm-function[175]:0x19ff0
at wasm://wasm/0058e82e:wasm-function[924]:0xad5ea
at wasm://wasm/0058e82e:wasm-function[387]:0x39bdc
at wasm://wasm/0058e82e:wasm-function[463]:0x4e5b1
at ret.<computed> (http://localhost/php-cgi-worker.mjs:9:380235)
at wasm://wasm/d3b27a3e:wasm-function[117]:0x1faf
at http://localhost/php-cgi-worker.mjs.wasm:wasm-function[1739]:0x2cf170
at http://localhost/php-cgi-worker.mjs.wasm:wasm-function[6296]:0x825491
================================================================================
STDERR:
================================================================================
STDOUT:
================================================================================
Looking at the stack trace: d3b27a3e:0x1faf was a call to call $env.sqlite3_open_v2
Also, even with the flag this test failed:
test('PHP_INT_SIZE', async () => {
const php = new PhpNode();
let stdOut = '', stdErr = '';
php.addEventListener('output', (event) => event.detail.forEach(line => void (stdOut += line)));
php.addEventListener('error', (event) => event.detail.forEach(line => void (stdErr += line)));
await php.binary;
const exitCode = await php.run(`<?php var_dump(PHP_INT_SIZE);`);
assert.equal(exitCode, 0);
assert.equal(stdOut, `int(4)\n`);
assert.equal(stdErr, '');
})
-s MEMORY64 assumes -sWASM_BIGINT which was crashing. Maybe this cannot be done quite yet
According to this table the Memory64 and bigint proposals are available in chrome 133 (4. Februar 2025) and ff 134 (7. January 2025) without feature flag. Maybe it's worth giving it another try?
Also, what is the size of size_t in this case? I'm trying to use int64_t for zend_long which crashes mostly because of SIZEOF_SIZE_T < SIZEOF_ZEND_LONG.