@php-wasm/node 1.1.2 → 1.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/asyncify/7_2_34/php_7_2.wasm +0 -0
- package/asyncify/7_3_33/php_7_3.wasm +0 -0
- package/asyncify/7_4_33/php_7_4.wasm +0 -0
- package/asyncify/8_0_30/php_8_0.wasm +0 -0
- package/asyncify/8_1_23/php_8_1.wasm +0 -0
- package/asyncify/8_2_10/php_8_2.wasm +0 -0
- package/asyncify/8_3_0/php_8_3.wasm +0 -0
- package/asyncify/8_4_0/php_8_4.wasm +0 -0
- package/asyncify/php_7_2.js +178 -24
- package/asyncify/php_7_3.js +178 -24
- package/asyncify/php_7_4.js +178 -24
- package/asyncify/php_8_0.js +178 -24
- package/asyncify/php_8_1.js +178 -24
- package/asyncify/php_8_2.js +178 -24
- package/asyncify/php_8_3.js +178 -24
- package/asyncify/php_8_4.js +178 -24
- package/index.cjs +2710 -1149
- package/index.js +2710 -1149
- package/jspi/7_2_34/php_7_2.wasm +0 -0
- package/jspi/7_3_33/php_7_3.wasm +0 -0
- package/jspi/7_4_33/php_7_4.wasm +0 -0
- package/jspi/8_0_30/php_8_0.wasm +0 -0
- package/jspi/8_1_23/php_8_1.wasm +0 -0
- package/jspi/8_2_10/php_8_2.wasm +0 -0
- package/jspi/8_3_0/php_8_3.wasm +0 -0
- package/jspi/8_4_0/php_8_4.wasm +0 -0
- package/jspi/php_7_2.js +175 -21
- package/jspi/php_7_3.js +175 -21
- package/jspi/php_7_4.js +7705 -8472
- package/jspi/php_8_0.js +175 -21
- package/jspi/php_8_1.js +175 -21
- package/jspi/php_8_2.js +175 -21
- package/jspi/php_8_3.js +175 -21
- package/jspi/php_8_4.js +175 -21
- package/package.json +8 -8
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/asyncify/php_7_2.js
CHANGED
|
@@ -8,7 +8,7 @@ import path from 'path';
|
|
|
8
8
|
|
|
9
9
|
const dependencyFilename = path.join(__dirname, '7_2_34', 'php_7_2.wasm');
|
|
10
10
|
export { dependencyFilename };
|
|
11
|
-
export const dependenciesTotalSize =
|
|
11
|
+
export const dependenciesTotalSize = 18094393;
|
|
12
12
|
export function init(RuntimeName, PHPLoader) {
|
|
13
13
|
// The rest of the code comes from the built php.js file and esm-suffix.js
|
|
14
14
|
// include: shell.js
|
|
@@ -7002,6 +7002,44 @@ export function init(RuntimeName, PHPLoader) {
|
|
|
7002
7002
|
// The files from the preload directory are preloaded using the
|
|
7003
7003
|
// auto_prepend_file php.ini directive.
|
|
7004
7004
|
FS.mkdir('/internal/shared/preload');
|
|
7005
|
+
// Create stdout and stderr devices. We can't just use Emscripten's
|
|
7006
|
+
// default stdout and stderr devices because they stop processing data
|
|
7007
|
+
// on the first null byte. However, when dealing with binary data,
|
|
7008
|
+
// null bytes are valid and common.
|
|
7009
|
+
FS.registerDevice(FS.makedev(64, 0), {
|
|
7010
|
+
open: () => {},
|
|
7011
|
+
close: () => {},
|
|
7012
|
+
read: () => 0,
|
|
7013
|
+
write: (stream, buffer, offset, length, pos) => {
|
|
7014
|
+
const chunk = buffer.subarray(offset, offset + length);
|
|
7015
|
+
PHPWASM.onStdout(chunk);
|
|
7016
|
+
return length;
|
|
7017
|
+
},
|
|
7018
|
+
});
|
|
7019
|
+
FS.mkdev('/internal/stdout', FS.makedev(64, 0));
|
|
7020
|
+
FS.registerDevice(FS.makedev(63, 0), {
|
|
7021
|
+
open: () => {},
|
|
7022
|
+
close: () => {},
|
|
7023
|
+
read: () => 0,
|
|
7024
|
+
write: (stream, buffer, offset, length, pos) => {
|
|
7025
|
+
const chunk = buffer.subarray(offset, offset + length);
|
|
7026
|
+
PHPWASM.onStderr(chunk);
|
|
7027
|
+
return length;
|
|
7028
|
+
},
|
|
7029
|
+
});
|
|
7030
|
+
FS.mkdev('/internal/stderr', FS.makedev(63, 0));
|
|
7031
|
+
FS.registerDevice(FS.makedev(62, 0), {
|
|
7032
|
+
open: () => {},
|
|
7033
|
+
close: () => {},
|
|
7034
|
+
read: () => 0,
|
|
7035
|
+
write: (stream, buffer, offset, length, pos) => {
|
|
7036
|
+
const chunk = buffer.subarray(offset, offset + length);
|
|
7037
|
+
PHPWASM.onHeaders(chunk);
|
|
7038
|
+
return length;
|
|
7039
|
+
},
|
|
7040
|
+
});
|
|
7041
|
+
FS.mkdev('/internal/headers', FS.makedev(62, 0));
|
|
7042
|
+
// Handle events.
|
|
7005
7043
|
PHPWASM.EventEmitter = ENVIRONMENT_IS_NODE
|
|
7006
7044
|
? require('events').EventEmitter
|
|
7007
7045
|
: class EventEmitter {
|
|
@@ -7042,9 +7080,71 @@ export function init(RuntimeName, PHPLoader) {
|
|
|
7042
7080
|
}
|
|
7043
7081
|
}
|
|
7044
7082
|
};
|
|
7083
|
+
// Clean up the fd -> childProcess mapping when the fd is closed:
|
|
7084
|
+
const originalClose = FS.close;
|
|
7085
|
+
FS.close = function (stream) {
|
|
7086
|
+
originalClose(stream);
|
|
7087
|
+
delete PHPWASM.child_proc_by_fd[stream.fd];
|
|
7088
|
+
};
|
|
7045
7089
|
PHPWASM.child_proc_by_fd = {};
|
|
7046
7090
|
PHPWASM.child_proc_by_pid = {};
|
|
7047
7091
|
PHPWASM.input_devices = {};
|
|
7092
|
+
const originalWrite = TTY.stream_ops.write;
|
|
7093
|
+
TTY.stream_ops.write = function (stream, ...rest) {
|
|
7094
|
+
const retval = originalWrite(stream, ...rest);
|
|
7095
|
+
// Implicit flush since PHP's fflush() doesn't seem to trigger the fsync event
|
|
7096
|
+
// @TODO: Fix this at the wasm level
|
|
7097
|
+
stream.tty.ops.fsync(stream.tty);
|
|
7098
|
+
return retval;
|
|
7099
|
+
};
|
|
7100
|
+
const originalPutChar = TTY.stream_ops.put_char;
|
|
7101
|
+
TTY.stream_ops.put_char = function (tty, val) {
|
|
7102
|
+
/**
|
|
7103
|
+
* Buffer newlines that Emscripten normally ignores.
|
|
7104
|
+
*
|
|
7105
|
+
* Emscripten doesn't do it by default because its default
|
|
7106
|
+
* print function is console.log that implicitly adds a newline. We are overwriting
|
|
7107
|
+
* it with an environment-specific function that outputs exaclty what it was given,
|
|
7108
|
+
* e.g. in Node.js it's process.stdout.write(). Therefore, we need to mak sure
|
|
7109
|
+
* all the newlines make it to the output buffer.
|
|
7110
|
+
*/ if (val === 10) tty.output.push(val);
|
|
7111
|
+
return originalPutChar(tty, val);
|
|
7112
|
+
};
|
|
7113
|
+
},
|
|
7114
|
+
onHeaders: function (chunk) {
|
|
7115
|
+
if (Module['onHeaders']) {
|
|
7116
|
+
Module['onHeaders'](chunk);
|
|
7117
|
+
return;
|
|
7118
|
+
}
|
|
7119
|
+
console.log('headers', {
|
|
7120
|
+
chunk,
|
|
7121
|
+
});
|
|
7122
|
+
},
|
|
7123
|
+
onStdout: function (chunk) {
|
|
7124
|
+
if (Module['onStdout']) {
|
|
7125
|
+
Module['onStdout'](chunk);
|
|
7126
|
+
return;
|
|
7127
|
+
}
|
|
7128
|
+
if (ENVIRONMENT_IS_NODE) {
|
|
7129
|
+
process.stdout.write(chunk);
|
|
7130
|
+
} else {
|
|
7131
|
+
console.log('stdout', {
|
|
7132
|
+
chunk,
|
|
7133
|
+
});
|
|
7134
|
+
}
|
|
7135
|
+
},
|
|
7136
|
+
onStderr: function (chunk) {
|
|
7137
|
+
if (Module['onStderr']) {
|
|
7138
|
+
Module['onStderr'](chunk);
|
|
7139
|
+
return;
|
|
7140
|
+
}
|
|
7141
|
+
if (ENVIRONMENT_IS_NODE) {
|
|
7142
|
+
process.stderr.write(chunk);
|
|
7143
|
+
} else {
|
|
7144
|
+
console.warn('stderr', {
|
|
7145
|
+
chunk,
|
|
7146
|
+
});
|
|
7147
|
+
}
|
|
7048
7148
|
},
|
|
7049
7149
|
getAllWebSockets: function (sock) {
|
|
7050
7150
|
const webSockets = new Set();
|
|
@@ -7226,7 +7326,7 @@ export function init(RuntimeName, PHPLoader) {
|
|
|
7226
7326
|
argsArray.push(UTF8ToString(HEAPU32[charPointer >> 2]));
|
|
7227
7327
|
}
|
|
7228
7328
|
}
|
|
7229
|
-
const cwdstr = cwdPtr ? UTF8ToString(cwdPtr) :
|
|
7329
|
+
const cwdstr = cwdPtr ? UTF8ToString(cwdPtr) : FS.cwd();
|
|
7230
7330
|
let envObject = null;
|
|
7231
7331
|
if (envLength) {
|
|
7232
7332
|
envObject = {};
|
|
@@ -7299,6 +7399,15 @@ export function init(RuntimeName, PHPLoader) {
|
|
|
7299
7399
|
PHPWASM.child_proc_by_fd[ProcInfo.stderrParentFd] = ProcInfo;
|
|
7300
7400
|
PHPWASM.child_proc_by_pid[ProcInfo.pid] = ProcInfo;
|
|
7301
7401
|
cp.on('exit', function (code) {
|
|
7402
|
+
for (const fd of [
|
|
7403
|
+
// The child process exited. Let's clean up its output streams:
|
|
7404
|
+
ProcInfo.stdoutChildFd,
|
|
7405
|
+
ProcInfo.stderrChildFd,
|
|
7406
|
+
]) {
|
|
7407
|
+
if (FS.streams[fd] && !FS.isClosed(FS.streams[fd])) {
|
|
7408
|
+
FS.close(FS.streams[fd]);
|
|
7409
|
+
}
|
|
7410
|
+
}
|
|
7302
7411
|
ProcInfo.exitCode = code;
|
|
7303
7412
|
ProcInfo.exited = true;
|
|
7304
7413
|
// Emit events for the wasm_poll_socket function.
|
|
@@ -7349,12 +7458,52 @@ export function init(RuntimeName, PHPLoader) {
|
|
|
7349
7458
|
* listen to the 'exit' event.
|
|
7350
7459
|
*/ try {
|
|
7351
7460
|
await new Promise((resolve, reject) => {
|
|
7352
|
-
|
|
7353
|
-
|
|
7461
|
+
/**
|
|
7462
|
+
* There was no `await` between the `spawnProcess` call
|
|
7463
|
+
* and the `await` below so the process haven't had a chance
|
|
7464
|
+
* to run any of the exit-related callbacks yet.
|
|
7465
|
+
*
|
|
7466
|
+
* Good.
|
|
7467
|
+
*
|
|
7468
|
+
* Let's listen to all the lifecycle events and resolve
|
|
7469
|
+
* the promise when the process starts or immediately crashes.
|
|
7470
|
+
*/ let resolved = false;
|
|
7471
|
+
cp.on('spawn', () => {
|
|
7472
|
+
if (resolved) return;
|
|
7473
|
+
resolved = true;
|
|
7474
|
+
resolve();
|
|
7475
|
+
});
|
|
7476
|
+
cp.on('error', (e) => {
|
|
7477
|
+
if (resolved) return;
|
|
7478
|
+
resolved = true;
|
|
7479
|
+
reject(e);
|
|
7480
|
+
});
|
|
7481
|
+
cp.on('exit', function (code) {
|
|
7482
|
+
if (resolved) return;
|
|
7483
|
+
resolved = true;
|
|
7484
|
+
if (code === 0) {
|
|
7485
|
+
resolve();
|
|
7486
|
+
} else {
|
|
7487
|
+
reject(
|
|
7488
|
+
new Error(`Process exited with code ${code}`)
|
|
7489
|
+
);
|
|
7490
|
+
}
|
|
7491
|
+
});
|
|
7492
|
+
/**
|
|
7493
|
+
* If the process haven't even started after 5 seconds, something
|
|
7494
|
+
* is wrong. Perhaps we're missing an event listener, or perhaps
|
|
7495
|
+
* the `spawnProcess` implementation failed to dispatch the relevant
|
|
7496
|
+
* event. Either way, let's crash to avoid blocking the proc_open()
|
|
7497
|
+
* call indefinitely.
|
|
7498
|
+
*/ setTimeout(() => {
|
|
7499
|
+
if (resolved) return;
|
|
7500
|
+
resolved = true;
|
|
7501
|
+
reject(new Error('Process timed out'));
|
|
7502
|
+
}, 5e3);
|
|
7354
7503
|
});
|
|
7355
7504
|
} catch (e) {
|
|
7356
7505
|
console.error(e);
|
|
7357
|
-
wakeUp(
|
|
7506
|
+
wakeUp(ProcInfo.pid);
|
|
7358
7507
|
return;
|
|
7359
7508
|
}
|
|
7360
7509
|
// Now we want to pass data from the STDIN source supplied by PHP
|
|
@@ -8239,14 +8388,7 @@ export function init(RuntimeName, PHPLoader) {
|
|
|
8239
8388
|
const POLLNVAL = 32;
|
|
8240
8389
|
return returnCallback((wakeUp) => {
|
|
8241
8390
|
const polls = [];
|
|
8242
|
-
if (socketd
|
|
8243
|
-
const procInfo = PHPWASM.child_proc_by_fd[socketd];
|
|
8244
|
-
if (procInfo.exited) {
|
|
8245
|
-
wakeUp(0);
|
|
8246
|
-
return;
|
|
8247
|
-
}
|
|
8248
|
-
polls.push(PHPWASM.awaitEvent(procInfo.stdout, 'data'));
|
|
8249
|
-
} else if (FS.isSocket(FS.getStream(socketd)?.node.mode)) {
|
|
8391
|
+
if (FS.isSocket(FS.getStream(socketd)?.node.mode)) {
|
|
8250
8392
|
const sock = getSocketFromFD(socketd);
|
|
8251
8393
|
if (!sock) {
|
|
8252
8394
|
wakeUp(0);
|
|
@@ -8280,7 +8422,12 @@ export function init(RuntimeName, PHPLoader) {
|
|
|
8280
8422
|
polls.push(PHPWASM.awaitConnection(ws));
|
|
8281
8423
|
lookingFor.add('POLLOUT');
|
|
8282
8424
|
}
|
|
8283
|
-
if (
|
|
8425
|
+
if (
|
|
8426
|
+
events & POLLHUP ||
|
|
8427
|
+
events & POLLIN ||
|
|
8428
|
+
events & POLLOUT ||
|
|
8429
|
+
events & POLLERR
|
|
8430
|
+
) {
|
|
8284
8431
|
polls.push(PHPWASM.awaitClose(ws));
|
|
8285
8432
|
lookingFor.add('POLLHUP');
|
|
8286
8433
|
}
|
|
@@ -8289,6 +8436,13 @@ export function init(RuntimeName, PHPLoader) {
|
|
|
8289
8436
|
lookingFor.add('POLLERR');
|
|
8290
8437
|
}
|
|
8291
8438
|
}
|
|
8439
|
+
} else if (socketd in PHPWASM.child_proc_by_fd) {
|
|
8440
|
+
const procInfo = PHPWASM.child_proc_by_fd[socketd];
|
|
8441
|
+
if (procInfo.exited) {
|
|
8442
|
+
wakeUp(0);
|
|
8443
|
+
return;
|
|
8444
|
+
}
|
|
8445
|
+
polls.push(PHPWASM.awaitEvent(procInfo.stdout, 'data'));
|
|
8292
8446
|
} else {
|
|
8293
8447
|
setTimeout(function () {
|
|
8294
8448
|
wakeUp(1);
|
|
@@ -8593,21 +8747,21 @@ export function init(RuntimeName, PHPLoader) {
|
|
|
8593
8747
|
a4
|
|
8594
8748
|
));
|
|
8595
8749
|
|
|
8596
|
-
var _wasm_add_cli_arg = (Module['_wasm_add_cli_arg'] = (a0) =>
|
|
8597
|
-
(_wasm_add_cli_arg = Module['_wasm_add_cli_arg'] = wasmExports['qb'])(
|
|
8598
|
-
a0
|
|
8599
|
-
));
|
|
8600
|
-
|
|
8601
|
-
var _run_cli = (Module['_run_cli'] = () =>
|
|
8602
|
-
(_run_cli = Module['_run_cli'] = wasmExports['rb'])());
|
|
8603
|
-
|
|
8604
8750
|
var _wasm_set_sapi_name = (Module['_wasm_set_sapi_name'] = (a0) =>
|
|
8605
8751
|
(_wasm_set_sapi_name = Module['_wasm_set_sapi_name'] =
|
|
8606
|
-
wasmExports['
|
|
8752
|
+
wasmExports['qb'])(a0));
|
|
8607
8753
|
|
|
8608
8754
|
var _wasm_set_phpini_path = (Module['_wasm_set_phpini_path'] = (a0) =>
|
|
8609
8755
|
(_wasm_set_phpini_path = Module['_wasm_set_phpini_path'] =
|
|
8610
|
-
wasmExports['
|
|
8756
|
+
wasmExports['rb'])(a0));
|
|
8757
|
+
|
|
8758
|
+
var _wasm_add_cli_arg = (Module['_wasm_add_cli_arg'] = (a0) =>
|
|
8759
|
+
(_wasm_add_cli_arg = Module['_wasm_add_cli_arg'] = wasmExports['sb'])(
|
|
8760
|
+
a0
|
|
8761
|
+
));
|
|
8762
|
+
|
|
8763
|
+
var _run_cli = (Module['_run_cli'] = () =>
|
|
8764
|
+
(_run_cli = Module['_run_cli'] = wasmExports['tb'])());
|
|
8611
8765
|
|
|
8612
8766
|
var _wasm_add_SERVER_entry = (Module['_wasm_add_SERVER_entry'] = (a0, a1) =>
|
|
8613
8767
|
(_wasm_add_SERVER_entry = Module['_wasm_add_SERVER_entry'] =
|
package/asyncify/php_7_3.js
CHANGED
|
@@ -8,7 +8,7 @@ import path from 'path';
|
|
|
8
8
|
|
|
9
9
|
const dependencyFilename = path.join(__dirname, '7_3_33', 'php_7_3.wasm');
|
|
10
10
|
export { dependencyFilename };
|
|
11
|
-
export const dependenciesTotalSize =
|
|
11
|
+
export const dependenciesTotalSize = 18173209;
|
|
12
12
|
export function init(RuntimeName, PHPLoader) {
|
|
13
13
|
// The rest of the code comes from the built php.js file and esm-suffix.js
|
|
14
14
|
// include: shell.js
|
|
@@ -7002,6 +7002,44 @@ export function init(RuntimeName, PHPLoader) {
|
|
|
7002
7002
|
// The files from the preload directory are preloaded using the
|
|
7003
7003
|
// auto_prepend_file php.ini directive.
|
|
7004
7004
|
FS.mkdir('/internal/shared/preload');
|
|
7005
|
+
// Create stdout and stderr devices. We can't just use Emscripten's
|
|
7006
|
+
// default stdout and stderr devices because they stop processing data
|
|
7007
|
+
// on the first null byte. However, when dealing with binary data,
|
|
7008
|
+
// null bytes are valid and common.
|
|
7009
|
+
FS.registerDevice(FS.makedev(64, 0), {
|
|
7010
|
+
open: () => {},
|
|
7011
|
+
close: () => {},
|
|
7012
|
+
read: () => 0,
|
|
7013
|
+
write: (stream, buffer, offset, length, pos) => {
|
|
7014
|
+
const chunk = buffer.subarray(offset, offset + length);
|
|
7015
|
+
PHPWASM.onStdout(chunk);
|
|
7016
|
+
return length;
|
|
7017
|
+
},
|
|
7018
|
+
});
|
|
7019
|
+
FS.mkdev('/internal/stdout', FS.makedev(64, 0));
|
|
7020
|
+
FS.registerDevice(FS.makedev(63, 0), {
|
|
7021
|
+
open: () => {},
|
|
7022
|
+
close: () => {},
|
|
7023
|
+
read: () => 0,
|
|
7024
|
+
write: (stream, buffer, offset, length, pos) => {
|
|
7025
|
+
const chunk = buffer.subarray(offset, offset + length);
|
|
7026
|
+
PHPWASM.onStderr(chunk);
|
|
7027
|
+
return length;
|
|
7028
|
+
},
|
|
7029
|
+
});
|
|
7030
|
+
FS.mkdev('/internal/stderr', FS.makedev(63, 0));
|
|
7031
|
+
FS.registerDevice(FS.makedev(62, 0), {
|
|
7032
|
+
open: () => {},
|
|
7033
|
+
close: () => {},
|
|
7034
|
+
read: () => 0,
|
|
7035
|
+
write: (stream, buffer, offset, length, pos) => {
|
|
7036
|
+
const chunk = buffer.subarray(offset, offset + length);
|
|
7037
|
+
PHPWASM.onHeaders(chunk);
|
|
7038
|
+
return length;
|
|
7039
|
+
},
|
|
7040
|
+
});
|
|
7041
|
+
FS.mkdev('/internal/headers', FS.makedev(62, 0));
|
|
7042
|
+
// Handle events.
|
|
7005
7043
|
PHPWASM.EventEmitter = ENVIRONMENT_IS_NODE
|
|
7006
7044
|
? require('events').EventEmitter
|
|
7007
7045
|
: class EventEmitter {
|
|
@@ -7042,9 +7080,71 @@ export function init(RuntimeName, PHPLoader) {
|
|
|
7042
7080
|
}
|
|
7043
7081
|
}
|
|
7044
7082
|
};
|
|
7083
|
+
// Clean up the fd -> childProcess mapping when the fd is closed:
|
|
7084
|
+
const originalClose = FS.close;
|
|
7085
|
+
FS.close = function (stream) {
|
|
7086
|
+
originalClose(stream);
|
|
7087
|
+
delete PHPWASM.child_proc_by_fd[stream.fd];
|
|
7088
|
+
};
|
|
7045
7089
|
PHPWASM.child_proc_by_fd = {};
|
|
7046
7090
|
PHPWASM.child_proc_by_pid = {};
|
|
7047
7091
|
PHPWASM.input_devices = {};
|
|
7092
|
+
const originalWrite = TTY.stream_ops.write;
|
|
7093
|
+
TTY.stream_ops.write = function (stream, ...rest) {
|
|
7094
|
+
const retval = originalWrite(stream, ...rest);
|
|
7095
|
+
// Implicit flush since PHP's fflush() doesn't seem to trigger the fsync event
|
|
7096
|
+
// @TODO: Fix this at the wasm level
|
|
7097
|
+
stream.tty.ops.fsync(stream.tty);
|
|
7098
|
+
return retval;
|
|
7099
|
+
};
|
|
7100
|
+
const originalPutChar = TTY.stream_ops.put_char;
|
|
7101
|
+
TTY.stream_ops.put_char = function (tty, val) {
|
|
7102
|
+
/**
|
|
7103
|
+
* Buffer newlines that Emscripten normally ignores.
|
|
7104
|
+
*
|
|
7105
|
+
* Emscripten doesn't do it by default because its default
|
|
7106
|
+
* print function is console.log that implicitly adds a newline. We are overwriting
|
|
7107
|
+
* it with an environment-specific function that outputs exaclty what it was given,
|
|
7108
|
+
* e.g. in Node.js it's process.stdout.write(). Therefore, we need to mak sure
|
|
7109
|
+
* all the newlines make it to the output buffer.
|
|
7110
|
+
*/ if (val === 10) tty.output.push(val);
|
|
7111
|
+
return originalPutChar(tty, val);
|
|
7112
|
+
};
|
|
7113
|
+
},
|
|
7114
|
+
onHeaders: function (chunk) {
|
|
7115
|
+
if (Module['onHeaders']) {
|
|
7116
|
+
Module['onHeaders'](chunk);
|
|
7117
|
+
return;
|
|
7118
|
+
}
|
|
7119
|
+
console.log('headers', {
|
|
7120
|
+
chunk,
|
|
7121
|
+
});
|
|
7122
|
+
},
|
|
7123
|
+
onStdout: function (chunk) {
|
|
7124
|
+
if (Module['onStdout']) {
|
|
7125
|
+
Module['onStdout'](chunk);
|
|
7126
|
+
return;
|
|
7127
|
+
}
|
|
7128
|
+
if (ENVIRONMENT_IS_NODE) {
|
|
7129
|
+
process.stdout.write(chunk);
|
|
7130
|
+
} else {
|
|
7131
|
+
console.log('stdout', {
|
|
7132
|
+
chunk,
|
|
7133
|
+
});
|
|
7134
|
+
}
|
|
7135
|
+
},
|
|
7136
|
+
onStderr: function (chunk) {
|
|
7137
|
+
if (Module['onStderr']) {
|
|
7138
|
+
Module['onStderr'](chunk);
|
|
7139
|
+
return;
|
|
7140
|
+
}
|
|
7141
|
+
if (ENVIRONMENT_IS_NODE) {
|
|
7142
|
+
process.stderr.write(chunk);
|
|
7143
|
+
} else {
|
|
7144
|
+
console.warn('stderr', {
|
|
7145
|
+
chunk,
|
|
7146
|
+
});
|
|
7147
|
+
}
|
|
7048
7148
|
},
|
|
7049
7149
|
getAllWebSockets: function (sock) {
|
|
7050
7150
|
const webSockets = new Set();
|
|
@@ -7226,7 +7326,7 @@ export function init(RuntimeName, PHPLoader) {
|
|
|
7226
7326
|
argsArray.push(UTF8ToString(HEAPU32[charPointer >> 2]));
|
|
7227
7327
|
}
|
|
7228
7328
|
}
|
|
7229
|
-
const cwdstr = cwdPtr ? UTF8ToString(cwdPtr) :
|
|
7329
|
+
const cwdstr = cwdPtr ? UTF8ToString(cwdPtr) : FS.cwd();
|
|
7230
7330
|
let envObject = null;
|
|
7231
7331
|
if (envLength) {
|
|
7232
7332
|
envObject = {};
|
|
@@ -7299,6 +7399,15 @@ export function init(RuntimeName, PHPLoader) {
|
|
|
7299
7399
|
PHPWASM.child_proc_by_fd[ProcInfo.stderrParentFd] = ProcInfo;
|
|
7300
7400
|
PHPWASM.child_proc_by_pid[ProcInfo.pid] = ProcInfo;
|
|
7301
7401
|
cp.on('exit', function (code) {
|
|
7402
|
+
for (const fd of [
|
|
7403
|
+
// The child process exited. Let's clean up its output streams:
|
|
7404
|
+
ProcInfo.stdoutChildFd,
|
|
7405
|
+
ProcInfo.stderrChildFd,
|
|
7406
|
+
]) {
|
|
7407
|
+
if (FS.streams[fd] && !FS.isClosed(FS.streams[fd])) {
|
|
7408
|
+
FS.close(FS.streams[fd]);
|
|
7409
|
+
}
|
|
7410
|
+
}
|
|
7302
7411
|
ProcInfo.exitCode = code;
|
|
7303
7412
|
ProcInfo.exited = true;
|
|
7304
7413
|
// Emit events for the wasm_poll_socket function.
|
|
@@ -7349,12 +7458,52 @@ export function init(RuntimeName, PHPLoader) {
|
|
|
7349
7458
|
* listen to the 'exit' event.
|
|
7350
7459
|
*/ try {
|
|
7351
7460
|
await new Promise((resolve, reject) => {
|
|
7352
|
-
|
|
7353
|
-
|
|
7461
|
+
/**
|
|
7462
|
+
* There was no `await` between the `spawnProcess` call
|
|
7463
|
+
* and the `await` below so the process haven't had a chance
|
|
7464
|
+
* to run any of the exit-related callbacks yet.
|
|
7465
|
+
*
|
|
7466
|
+
* Good.
|
|
7467
|
+
*
|
|
7468
|
+
* Let's listen to all the lifecycle events and resolve
|
|
7469
|
+
* the promise when the process starts or immediately crashes.
|
|
7470
|
+
*/ let resolved = false;
|
|
7471
|
+
cp.on('spawn', () => {
|
|
7472
|
+
if (resolved) return;
|
|
7473
|
+
resolved = true;
|
|
7474
|
+
resolve();
|
|
7475
|
+
});
|
|
7476
|
+
cp.on('error', (e) => {
|
|
7477
|
+
if (resolved) return;
|
|
7478
|
+
resolved = true;
|
|
7479
|
+
reject(e);
|
|
7480
|
+
});
|
|
7481
|
+
cp.on('exit', function (code) {
|
|
7482
|
+
if (resolved) return;
|
|
7483
|
+
resolved = true;
|
|
7484
|
+
if (code === 0) {
|
|
7485
|
+
resolve();
|
|
7486
|
+
} else {
|
|
7487
|
+
reject(
|
|
7488
|
+
new Error(`Process exited with code ${code}`)
|
|
7489
|
+
);
|
|
7490
|
+
}
|
|
7491
|
+
});
|
|
7492
|
+
/**
|
|
7493
|
+
* If the process haven't even started after 5 seconds, something
|
|
7494
|
+
* is wrong. Perhaps we're missing an event listener, or perhaps
|
|
7495
|
+
* the `spawnProcess` implementation failed to dispatch the relevant
|
|
7496
|
+
* event. Either way, let's crash to avoid blocking the proc_open()
|
|
7497
|
+
* call indefinitely.
|
|
7498
|
+
*/ setTimeout(() => {
|
|
7499
|
+
if (resolved) return;
|
|
7500
|
+
resolved = true;
|
|
7501
|
+
reject(new Error('Process timed out'));
|
|
7502
|
+
}, 5e3);
|
|
7354
7503
|
});
|
|
7355
7504
|
} catch (e) {
|
|
7356
7505
|
console.error(e);
|
|
7357
|
-
wakeUp(
|
|
7506
|
+
wakeUp(ProcInfo.pid);
|
|
7358
7507
|
return;
|
|
7359
7508
|
}
|
|
7360
7509
|
// Now we want to pass data from the STDIN source supplied by PHP
|
|
@@ -8239,14 +8388,7 @@ export function init(RuntimeName, PHPLoader) {
|
|
|
8239
8388
|
const POLLNVAL = 32;
|
|
8240
8389
|
return returnCallback((wakeUp) => {
|
|
8241
8390
|
const polls = [];
|
|
8242
|
-
if (socketd
|
|
8243
|
-
const procInfo = PHPWASM.child_proc_by_fd[socketd];
|
|
8244
|
-
if (procInfo.exited) {
|
|
8245
|
-
wakeUp(0);
|
|
8246
|
-
return;
|
|
8247
|
-
}
|
|
8248
|
-
polls.push(PHPWASM.awaitEvent(procInfo.stdout, 'data'));
|
|
8249
|
-
} else if (FS.isSocket(FS.getStream(socketd)?.node.mode)) {
|
|
8391
|
+
if (FS.isSocket(FS.getStream(socketd)?.node.mode)) {
|
|
8250
8392
|
const sock = getSocketFromFD(socketd);
|
|
8251
8393
|
if (!sock) {
|
|
8252
8394
|
wakeUp(0);
|
|
@@ -8280,7 +8422,12 @@ export function init(RuntimeName, PHPLoader) {
|
|
|
8280
8422
|
polls.push(PHPWASM.awaitConnection(ws));
|
|
8281
8423
|
lookingFor.add('POLLOUT');
|
|
8282
8424
|
}
|
|
8283
|
-
if (
|
|
8425
|
+
if (
|
|
8426
|
+
events & POLLHUP ||
|
|
8427
|
+
events & POLLIN ||
|
|
8428
|
+
events & POLLOUT ||
|
|
8429
|
+
events & POLLERR
|
|
8430
|
+
) {
|
|
8284
8431
|
polls.push(PHPWASM.awaitClose(ws));
|
|
8285
8432
|
lookingFor.add('POLLHUP');
|
|
8286
8433
|
}
|
|
@@ -8289,6 +8436,13 @@ export function init(RuntimeName, PHPLoader) {
|
|
|
8289
8436
|
lookingFor.add('POLLERR');
|
|
8290
8437
|
}
|
|
8291
8438
|
}
|
|
8439
|
+
} else if (socketd in PHPWASM.child_proc_by_fd) {
|
|
8440
|
+
const procInfo = PHPWASM.child_proc_by_fd[socketd];
|
|
8441
|
+
if (procInfo.exited) {
|
|
8442
|
+
wakeUp(0);
|
|
8443
|
+
return;
|
|
8444
|
+
}
|
|
8445
|
+
polls.push(PHPWASM.awaitEvent(procInfo.stdout, 'data'));
|
|
8292
8446
|
} else {
|
|
8293
8447
|
setTimeout(function () {
|
|
8294
8448
|
wakeUp(1);
|
|
@@ -8593,21 +8747,21 @@ export function init(RuntimeName, PHPLoader) {
|
|
|
8593
8747
|
a4
|
|
8594
8748
|
));
|
|
8595
8749
|
|
|
8596
|
-
var _wasm_add_cli_arg = (Module['_wasm_add_cli_arg'] = (a0) =>
|
|
8597
|
-
(_wasm_add_cli_arg = Module['_wasm_add_cli_arg'] = wasmExports['qb'])(
|
|
8598
|
-
a0
|
|
8599
|
-
));
|
|
8600
|
-
|
|
8601
|
-
var _run_cli = (Module['_run_cli'] = () =>
|
|
8602
|
-
(_run_cli = Module['_run_cli'] = wasmExports['rb'])());
|
|
8603
|
-
|
|
8604
8750
|
var _wasm_set_sapi_name = (Module['_wasm_set_sapi_name'] = (a0) =>
|
|
8605
8751
|
(_wasm_set_sapi_name = Module['_wasm_set_sapi_name'] =
|
|
8606
|
-
wasmExports['
|
|
8752
|
+
wasmExports['qb'])(a0));
|
|
8607
8753
|
|
|
8608
8754
|
var _wasm_set_phpini_path = (Module['_wasm_set_phpini_path'] = (a0) =>
|
|
8609
8755
|
(_wasm_set_phpini_path = Module['_wasm_set_phpini_path'] =
|
|
8610
|
-
wasmExports['
|
|
8756
|
+
wasmExports['rb'])(a0));
|
|
8757
|
+
|
|
8758
|
+
var _wasm_add_cli_arg = (Module['_wasm_add_cli_arg'] = (a0) =>
|
|
8759
|
+
(_wasm_add_cli_arg = Module['_wasm_add_cli_arg'] = wasmExports['sb'])(
|
|
8760
|
+
a0
|
|
8761
|
+
));
|
|
8762
|
+
|
|
8763
|
+
var _run_cli = (Module['_run_cli'] = () =>
|
|
8764
|
+
(_run_cli = Module['_run_cli'] = wasmExports['tb'])());
|
|
8611
8765
|
|
|
8612
8766
|
var _wasm_add_SERVER_entry = (Module['_wasm_add_SERVER_entry'] = (a0, a1) =>
|
|
8613
8767
|
(_wasm_add_SERVER_entry = Module['_wasm_add_SERVER_entry'] =
|