@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
package/asyncify/php_8_1.js
CHANGED
|
@@ -8,7 +8,7 @@ import path from 'path';
|
|
|
8
8
|
|
|
9
9
|
const dependencyFilename = path.join(__dirname, '8_1_23', 'php_8_1.wasm');
|
|
10
10
|
export { dependencyFilename };
|
|
11
|
-
export const dependenciesTotalSize =
|
|
11
|
+
export const dependenciesTotalSize = 17369361;
|
|
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
|
|
@@ -7030,6 +7030,44 @@ export function init(RuntimeName, PHPLoader) {
|
|
|
7030
7030
|
// The files from the preload directory are preloaded using the
|
|
7031
7031
|
// auto_prepend_file php.ini directive.
|
|
7032
7032
|
FS.mkdir('/internal/shared/preload');
|
|
7033
|
+
// Create stdout and stderr devices. We can't just use Emscripten's
|
|
7034
|
+
// default stdout and stderr devices because they stop processing data
|
|
7035
|
+
// on the first null byte. However, when dealing with binary data,
|
|
7036
|
+
// null bytes are valid and common.
|
|
7037
|
+
FS.registerDevice(FS.makedev(64, 0), {
|
|
7038
|
+
open: () => {},
|
|
7039
|
+
close: () => {},
|
|
7040
|
+
read: () => 0,
|
|
7041
|
+
write: (stream, buffer, offset, length, pos) => {
|
|
7042
|
+
const chunk = buffer.subarray(offset, offset + length);
|
|
7043
|
+
PHPWASM.onStdout(chunk);
|
|
7044
|
+
return length;
|
|
7045
|
+
},
|
|
7046
|
+
});
|
|
7047
|
+
FS.mkdev('/internal/stdout', FS.makedev(64, 0));
|
|
7048
|
+
FS.registerDevice(FS.makedev(63, 0), {
|
|
7049
|
+
open: () => {},
|
|
7050
|
+
close: () => {},
|
|
7051
|
+
read: () => 0,
|
|
7052
|
+
write: (stream, buffer, offset, length, pos) => {
|
|
7053
|
+
const chunk = buffer.subarray(offset, offset + length);
|
|
7054
|
+
PHPWASM.onStderr(chunk);
|
|
7055
|
+
return length;
|
|
7056
|
+
},
|
|
7057
|
+
});
|
|
7058
|
+
FS.mkdev('/internal/stderr', FS.makedev(63, 0));
|
|
7059
|
+
FS.registerDevice(FS.makedev(62, 0), {
|
|
7060
|
+
open: () => {},
|
|
7061
|
+
close: () => {},
|
|
7062
|
+
read: () => 0,
|
|
7063
|
+
write: (stream, buffer, offset, length, pos) => {
|
|
7064
|
+
const chunk = buffer.subarray(offset, offset + length);
|
|
7065
|
+
PHPWASM.onHeaders(chunk);
|
|
7066
|
+
return length;
|
|
7067
|
+
},
|
|
7068
|
+
});
|
|
7069
|
+
FS.mkdev('/internal/headers', FS.makedev(62, 0));
|
|
7070
|
+
// Handle events.
|
|
7033
7071
|
PHPWASM.EventEmitter = ENVIRONMENT_IS_NODE
|
|
7034
7072
|
? require('events').EventEmitter
|
|
7035
7073
|
: class EventEmitter {
|
|
@@ -7070,9 +7108,71 @@ export function init(RuntimeName, PHPLoader) {
|
|
|
7070
7108
|
}
|
|
7071
7109
|
}
|
|
7072
7110
|
};
|
|
7111
|
+
// Clean up the fd -> childProcess mapping when the fd is closed:
|
|
7112
|
+
const originalClose = FS.close;
|
|
7113
|
+
FS.close = function (stream) {
|
|
7114
|
+
originalClose(stream);
|
|
7115
|
+
delete PHPWASM.child_proc_by_fd[stream.fd];
|
|
7116
|
+
};
|
|
7073
7117
|
PHPWASM.child_proc_by_fd = {};
|
|
7074
7118
|
PHPWASM.child_proc_by_pid = {};
|
|
7075
7119
|
PHPWASM.input_devices = {};
|
|
7120
|
+
const originalWrite = TTY.stream_ops.write;
|
|
7121
|
+
TTY.stream_ops.write = function (stream, ...rest) {
|
|
7122
|
+
const retval = originalWrite(stream, ...rest);
|
|
7123
|
+
// Implicit flush since PHP's fflush() doesn't seem to trigger the fsync event
|
|
7124
|
+
// @TODO: Fix this at the wasm level
|
|
7125
|
+
stream.tty.ops.fsync(stream.tty);
|
|
7126
|
+
return retval;
|
|
7127
|
+
};
|
|
7128
|
+
const originalPutChar = TTY.stream_ops.put_char;
|
|
7129
|
+
TTY.stream_ops.put_char = function (tty, val) {
|
|
7130
|
+
/**
|
|
7131
|
+
* Buffer newlines that Emscripten normally ignores.
|
|
7132
|
+
*
|
|
7133
|
+
* Emscripten doesn't do it by default because its default
|
|
7134
|
+
* print function is console.log that implicitly adds a newline. We are overwriting
|
|
7135
|
+
* it with an environment-specific function that outputs exaclty what it was given,
|
|
7136
|
+
* e.g. in Node.js it's process.stdout.write(). Therefore, we need to mak sure
|
|
7137
|
+
* all the newlines make it to the output buffer.
|
|
7138
|
+
*/ if (val === 10) tty.output.push(val);
|
|
7139
|
+
return originalPutChar(tty, val);
|
|
7140
|
+
};
|
|
7141
|
+
},
|
|
7142
|
+
onHeaders: function (chunk) {
|
|
7143
|
+
if (Module['onHeaders']) {
|
|
7144
|
+
Module['onHeaders'](chunk);
|
|
7145
|
+
return;
|
|
7146
|
+
}
|
|
7147
|
+
console.log('headers', {
|
|
7148
|
+
chunk,
|
|
7149
|
+
});
|
|
7150
|
+
},
|
|
7151
|
+
onStdout: function (chunk) {
|
|
7152
|
+
if (Module['onStdout']) {
|
|
7153
|
+
Module['onStdout'](chunk);
|
|
7154
|
+
return;
|
|
7155
|
+
}
|
|
7156
|
+
if (ENVIRONMENT_IS_NODE) {
|
|
7157
|
+
process.stdout.write(chunk);
|
|
7158
|
+
} else {
|
|
7159
|
+
console.log('stdout', {
|
|
7160
|
+
chunk,
|
|
7161
|
+
});
|
|
7162
|
+
}
|
|
7163
|
+
},
|
|
7164
|
+
onStderr: function (chunk) {
|
|
7165
|
+
if (Module['onStderr']) {
|
|
7166
|
+
Module['onStderr'](chunk);
|
|
7167
|
+
return;
|
|
7168
|
+
}
|
|
7169
|
+
if (ENVIRONMENT_IS_NODE) {
|
|
7170
|
+
process.stderr.write(chunk);
|
|
7171
|
+
} else {
|
|
7172
|
+
console.warn('stderr', {
|
|
7173
|
+
chunk,
|
|
7174
|
+
});
|
|
7175
|
+
}
|
|
7076
7176
|
},
|
|
7077
7177
|
getAllWebSockets: function (sock) {
|
|
7078
7178
|
const webSockets = new Set();
|
|
@@ -7254,7 +7354,7 @@ export function init(RuntimeName, PHPLoader) {
|
|
|
7254
7354
|
argsArray.push(UTF8ToString(HEAPU32[charPointer >> 2]));
|
|
7255
7355
|
}
|
|
7256
7356
|
}
|
|
7257
|
-
const cwdstr = cwdPtr ? UTF8ToString(cwdPtr) :
|
|
7357
|
+
const cwdstr = cwdPtr ? UTF8ToString(cwdPtr) : FS.cwd();
|
|
7258
7358
|
let envObject = null;
|
|
7259
7359
|
if (envLength) {
|
|
7260
7360
|
envObject = {};
|
|
@@ -7327,6 +7427,15 @@ export function init(RuntimeName, PHPLoader) {
|
|
|
7327
7427
|
PHPWASM.child_proc_by_fd[ProcInfo.stderrParentFd] = ProcInfo;
|
|
7328
7428
|
PHPWASM.child_proc_by_pid[ProcInfo.pid] = ProcInfo;
|
|
7329
7429
|
cp.on('exit', function (code) {
|
|
7430
|
+
for (const fd of [
|
|
7431
|
+
// The child process exited. Let's clean up its output streams:
|
|
7432
|
+
ProcInfo.stdoutChildFd,
|
|
7433
|
+
ProcInfo.stderrChildFd,
|
|
7434
|
+
]) {
|
|
7435
|
+
if (FS.streams[fd] && !FS.isClosed(FS.streams[fd])) {
|
|
7436
|
+
FS.close(FS.streams[fd]);
|
|
7437
|
+
}
|
|
7438
|
+
}
|
|
7330
7439
|
ProcInfo.exitCode = code;
|
|
7331
7440
|
ProcInfo.exited = true;
|
|
7332
7441
|
// Emit events for the wasm_poll_socket function.
|
|
@@ -7377,12 +7486,52 @@ export function init(RuntimeName, PHPLoader) {
|
|
|
7377
7486
|
* listen to the 'exit' event.
|
|
7378
7487
|
*/ try {
|
|
7379
7488
|
await new Promise((resolve, reject) => {
|
|
7380
|
-
|
|
7381
|
-
|
|
7489
|
+
/**
|
|
7490
|
+
* There was no `await` between the `spawnProcess` call
|
|
7491
|
+
* and the `await` below so the process haven't had a chance
|
|
7492
|
+
* to run any of the exit-related callbacks yet.
|
|
7493
|
+
*
|
|
7494
|
+
* Good.
|
|
7495
|
+
*
|
|
7496
|
+
* Let's listen to all the lifecycle events and resolve
|
|
7497
|
+
* the promise when the process starts or immediately crashes.
|
|
7498
|
+
*/ let resolved = false;
|
|
7499
|
+
cp.on('spawn', () => {
|
|
7500
|
+
if (resolved) return;
|
|
7501
|
+
resolved = true;
|
|
7502
|
+
resolve();
|
|
7503
|
+
});
|
|
7504
|
+
cp.on('error', (e) => {
|
|
7505
|
+
if (resolved) return;
|
|
7506
|
+
resolved = true;
|
|
7507
|
+
reject(e);
|
|
7508
|
+
});
|
|
7509
|
+
cp.on('exit', function (code) {
|
|
7510
|
+
if (resolved) return;
|
|
7511
|
+
resolved = true;
|
|
7512
|
+
if (code === 0) {
|
|
7513
|
+
resolve();
|
|
7514
|
+
} else {
|
|
7515
|
+
reject(
|
|
7516
|
+
new Error(`Process exited with code ${code}`)
|
|
7517
|
+
);
|
|
7518
|
+
}
|
|
7519
|
+
});
|
|
7520
|
+
/**
|
|
7521
|
+
* If the process haven't even started after 5 seconds, something
|
|
7522
|
+
* is wrong. Perhaps we're missing an event listener, or perhaps
|
|
7523
|
+
* the `spawnProcess` implementation failed to dispatch the relevant
|
|
7524
|
+
* event. Either way, let's crash to avoid blocking the proc_open()
|
|
7525
|
+
* call indefinitely.
|
|
7526
|
+
*/ setTimeout(() => {
|
|
7527
|
+
if (resolved) return;
|
|
7528
|
+
resolved = true;
|
|
7529
|
+
reject(new Error('Process timed out'));
|
|
7530
|
+
}, 5e3);
|
|
7382
7531
|
});
|
|
7383
7532
|
} catch (e) {
|
|
7384
7533
|
console.error(e);
|
|
7385
|
-
wakeUp(
|
|
7534
|
+
wakeUp(ProcInfo.pid);
|
|
7386
7535
|
return;
|
|
7387
7536
|
}
|
|
7388
7537
|
// Now we want to pass data from the STDIN source supplied by PHP
|
|
@@ -8275,14 +8424,7 @@ export function init(RuntimeName, PHPLoader) {
|
|
|
8275
8424
|
const POLLNVAL = 32;
|
|
8276
8425
|
return returnCallback((wakeUp) => {
|
|
8277
8426
|
const polls = [];
|
|
8278
|
-
if (socketd
|
|
8279
|
-
const procInfo = PHPWASM.child_proc_by_fd[socketd];
|
|
8280
|
-
if (procInfo.exited) {
|
|
8281
|
-
wakeUp(0);
|
|
8282
|
-
return;
|
|
8283
|
-
}
|
|
8284
|
-
polls.push(PHPWASM.awaitEvent(procInfo.stdout, 'data'));
|
|
8285
|
-
} else if (FS.isSocket(FS.getStream(socketd)?.node.mode)) {
|
|
8427
|
+
if (FS.isSocket(FS.getStream(socketd)?.node.mode)) {
|
|
8286
8428
|
const sock = getSocketFromFD(socketd);
|
|
8287
8429
|
if (!sock) {
|
|
8288
8430
|
wakeUp(0);
|
|
@@ -8316,7 +8458,12 @@ export function init(RuntimeName, PHPLoader) {
|
|
|
8316
8458
|
polls.push(PHPWASM.awaitConnection(ws));
|
|
8317
8459
|
lookingFor.add('POLLOUT');
|
|
8318
8460
|
}
|
|
8319
|
-
if (
|
|
8461
|
+
if (
|
|
8462
|
+
events & POLLHUP ||
|
|
8463
|
+
events & POLLIN ||
|
|
8464
|
+
events & POLLOUT ||
|
|
8465
|
+
events & POLLERR
|
|
8466
|
+
) {
|
|
8320
8467
|
polls.push(PHPWASM.awaitClose(ws));
|
|
8321
8468
|
lookingFor.add('POLLHUP');
|
|
8322
8469
|
}
|
|
@@ -8325,6 +8472,13 @@ export function init(RuntimeName, PHPLoader) {
|
|
|
8325
8472
|
lookingFor.add('POLLERR');
|
|
8326
8473
|
}
|
|
8327
8474
|
}
|
|
8475
|
+
} else if (socketd in PHPWASM.child_proc_by_fd) {
|
|
8476
|
+
const procInfo = PHPWASM.child_proc_by_fd[socketd];
|
|
8477
|
+
if (procInfo.exited) {
|
|
8478
|
+
wakeUp(0);
|
|
8479
|
+
return;
|
|
8480
|
+
}
|
|
8481
|
+
polls.push(PHPWASM.awaitEvent(procInfo.stdout, 'data'));
|
|
8328
8482
|
} else {
|
|
8329
8483
|
setTimeout(function () {
|
|
8330
8484
|
wakeUp(1);
|
|
@@ -8636,21 +8790,21 @@ export function init(RuntimeName, PHPLoader) {
|
|
|
8636
8790
|
a4
|
|
8637
8791
|
));
|
|
8638
8792
|
|
|
8639
|
-
var _wasm_add_cli_arg = (Module['_wasm_add_cli_arg'] = (a0) =>
|
|
8640
|
-
(_wasm_add_cli_arg = Module['_wasm_add_cli_arg'] = wasmExports['xb'])(
|
|
8641
|
-
a0
|
|
8642
|
-
));
|
|
8643
|
-
|
|
8644
|
-
var _run_cli = (Module['_run_cli'] = () =>
|
|
8645
|
-
(_run_cli = Module['_run_cli'] = wasmExports['yb'])());
|
|
8646
|
-
|
|
8647
8793
|
var _wasm_set_sapi_name = (Module['_wasm_set_sapi_name'] = (a0) =>
|
|
8648
8794
|
(_wasm_set_sapi_name = Module['_wasm_set_sapi_name'] =
|
|
8649
|
-
wasmExports['
|
|
8795
|
+
wasmExports['xb'])(a0));
|
|
8650
8796
|
|
|
8651
8797
|
var _wasm_set_phpini_path = (Module['_wasm_set_phpini_path'] = (a0) =>
|
|
8652
8798
|
(_wasm_set_phpini_path = Module['_wasm_set_phpini_path'] =
|
|
8653
|
-
wasmExports['
|
|
8799
|
+
wasmExports['yb'])(a0));
|
|
8800
|
+
|
|
8801
|
+
var _wasm_add_cli_arg = (Module['_wasm_add_cli_arg'] = (a0) =>
|
|
8802
|
+
(_wasm_add_cli_arg = Module['_wasm_add_cli_arg'] = wasmExports['zb'])(
|
|
8803
|
+
a0
|
|
8804
|
+
));
|
|
8805
|
+
|
|
8806
|
+
var _run_cli = (Module['_run_cli'] = () =>
|
|
8807
|
+
(_run_cli = Module['_run_cli'] = wasmExports['Ab'])());
|
|
8654
8808
|
|
|
8655
8809
|
var _wasm_add_SERVER_entry = (Module['_wasm_add_SERVER_entry'] = (a0, a1) =>
|
|
8656
8810
|
(_wasm_add_SERVER_entry = Module['_wasm_add_SERVER_entry'] =
|
package/asyncify/php_8_2.js
CHANGED
|
@@ -8,7 +8,7 @@ import path from 'path';
|
|
|
8
8
|
|
|
9
9
|
const dependencyFilename = path.join(__dirname, '8_2_10', 'php_8_2.wasm');
|
|
10
10
|
export { dependencyFilename };
|
|
11
|
-
export const dependenciesTotalSize =
|
|
11
|
+
export const dependenciesTotalSize = 17712674;
|
|
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
|
|
@@ -7032,6 +7032,44 @@ export function init(RuntimeName, PHPLoader) {
|
|
|
7032
7032
|
// The files from the preload directory are preloaded using the
|
|
7033
7033
|
// auto_prepend_file php.ini directive.
|
|
7034
7034
|
FS.mkdir('/internal/shared/preload');
|
|
7035
|
+
// Create stdout and stderr devices. We can't just use Emscripten's
|
|
7036
|
+
// default stdout and stderr devices because they stop processing data
|
|
7037
|
+
// on the first null byte. However, when dealing with binary data,
|
|
7038
|
+
// null bytes are valid and common.
|
|
7039
|
+
FS.registerDevice(FS.makedev(64, 0), {
|
|
7040
|
+
open: () => {},
|
|
7041
|
+
close: () => {},
|
|
7042
|
+
read: () => 0,
|
|
7043
|
+
write: (stream, buffer, offset, length, pos) => {
|
|
7044
|
+
const chunk = buffer.subarray(offset, offset + length);
|
|
7045
|
+
PHPWASM.onStdout(chunk);
|
|
7046
|
+
return length;
|
|
7047
|
+
},
|
|
7048
|
+
});
|
|
7049
|
+
FS.mkdev('/internal/stdout', FS.makedev(64, 0));
|
|
7050
|
+
FS.registerDevice(FS.makedev(63, 0), {
|
|
7051
|
+
open: () => {},
|
|
7052
|
+
close: () => {},
|
|
7053
|
+
read: () => 0,
|
|
7054
|
+
write: (stream, buffer, offset, length, pos) => {
|
|
7055
|
+
const chunk = buffer.subarray(offset, offset + length);
|
|
7056
|
+
PHPWASM.onStderr(chunk);
|
|
7057
|
+
return length;
|
|
7058
|
+
},
|
|
7059
|
+
});
|
|
7060
|
+
FS.mkdev('/internal/stderr', FS.makedev(63, 0));
|
|
7061
|
+
FS.registerDevice(FS.makedev(62, 0), {
|
|
7062
|
+
open: () => {},
|
|
7063
|
+
close: () => {},
|
|
7064
|
+
read: () => 0,
|
|
7065
|
+
write: (stream, buffer, offset, length, pos) => {
|
|
7066
|
+
const chunk = buffer.subarray(offset, offset + length);
|
|
7067
|
+
PHPWASM.onHeaders(chunk);
|
|
7068
|
+
return length;
|
|
7069
|
+
},
|
|
7070
|
+
});
|
|
7071
|
+
FS.mkdev('/internal/headers', FS.makedev(62, 0));
|
|
7072
|
+
// Handle events.
|
|
7035
7073
|
PHPWASM.EventEmitter = ENVIRONMENT_IS_NODE
|
|
7036
7074
|
? require('events').EventEmitter
|
|
7037
7075
|
: class EventEmitter {
|
|
@@ -7072,9 +7110,71 @@ export function init(RuntimeName, PHPLoader) {
|
|
|
7072
7110
|
}
|
|
7073
7111
|
}
|
|
7074
7112
|
};
|
|
7113
|
+
// Clean up the fd -> childProcess mapping when the fd is closed:
|
|
7114
|
+
const originalClose = FS.close;
|
|
7115
|
+
FS.close = function (stream) {
|
|
7116
|
+
originalClose(stream);
|
|
7117
|
+
delete PHPWASM.child_proc_by_fd[stream.fd];
|
|
7118
|
+
};
|
|
7075
7119
|
PHPWASM.child_proc_by_fd = {};
|
|
7076
7120
|
PHPWASM.child_proc_by_pid = {};
|
|
7077
7121
|
PHPWASM.input_devices = {};
|
|
7122
|
+
const originalWrite = TTY.stream_ops.write;
|
|
7123
|
+
TTY.stream_ops.write = function (stream, ...rest) {
|
|
7124
|
+
const retval = originalWrite(stream, ...rest);
|
|
7125
|
+
// Implicit flush since PHP's fflush() doesn't seem to trigger the fsync event
|
|
7126
|
+
// @TODO: Fix this at the wasm level
|
|
7127
|
+
stream.tty.ops.fsync(stream.tty);
|
|
7128
|
+
return retval;
|
|
7129
|
+
};
|
|
7130
|
+
const originalPutChar = TTY.stream_ops.put_char;
|
|
7131
|
+
TTY.stream_ops.put_char = function (tty, val) {
|
|
7132
|
+
/**
|
|
7133
|
+
* Buffer newlines that Emscripten normally ignores.
|
|
7134
|
+
*
|
|
7135
|
+
* Emscripten doesn't do it by default because its default
|
|
7136
|
+
* print function is console.log that implicitly adds a newline. We are overwriting
|
|
7137
|
+
* it with an environment-specific function that outputs exaclty what it was given,
|
|
7138
|
+
* e.g. in Node.js it's process.stdout.write(). Therefore, we need to mak sure
|
|
7139
|
+
* all the newlines make it to the output buffer.
|
|
7140
|
+
*/ if (val === 10) tty.output.push(val);
|
|
7141
|
+
return originalPutChar(tty, val);
|
|
7142
|
+
};
|
|
7143
|
+
},
|
|
7144
|
+
onHeaders: function (chunk) {
|
|
7145
|
+
if (Module['onHeaders']) {
|
|
7146
|
+
Module['onHeaders'](chunk);
|
|
7147
|
+
return;
|
|
7148
|
+
}
|
|
7149
|
+
console.log('headers', {
|
|
7150
|
+
chunk,
|
|
7151
|
+
});
|
|
7152
|
+
},
|
|
7153
|
+
onStdout: function (chunk) {
|
|
7154
|
+
if (Module['onStdout']) {
|
|
7155
|
+
Module['onStdout'](chunk);
|
|
7156
|
+
return;
|
|
7157
|
+
}
|
|
7158
|
+
if (ENVIRONMENT_IS_NODE) {
|
|
7159
|
+
process.stdout.write(chunk);
|
|
7160
|
+
} else {
|
|
7161
|
+
console.log('stdout', {
|
|
7162
|
+
chunk,
|
|
7163
|
+
});
|
|
7164
|
+
}
|
|
7165
|
+
},
|
|
7166
|
+
onStderr: function (chunk) {
|
|
7167
|
+
if (Module['onStderr']) {
|
|
7168
|
+
Module['onStderr'](chunk);
|
|
7169
|
+
return;
|
|
7170
|
+
}
|
|
7171
|
+
if (ENVIRONMENT_IS_NODE) {
|
|
7172
|
+
process.stderr.write(chunk);
|
|
7173
|
+
} else {
|
|
7174
|
+
console.warn('stderr', {
|
|
7175
|
+
chunk,
|
|
7176
|
+
});
|
|
7177
|
+
}
|
|
7078
7178
|
},
|
|
7079
7179
|
getAllWebSockets: function (sock) {
|
|
7080
7180
|
const webSockets = new Set();
|
|
@@ -7256,7 +7356,7 @@ export function init(RuntimeName, PHPLoader) {
|
|
|
7256
7356
|
argsArray.push(UTF8ToString(HEAPU32[charPointer >> 2]));
|
|
7257
7357
|
}
|
|
7258
7358
|
}
|
|
7259
|
-
const cwdstr = cwdPtr ? UTF8ToString(cwdPtr) :
|
|
7359
|
+
const cwdstr = cwdPtr ? UTF8ToString(cwdPtr) : FS.cwd();
|
|
7260
7360
|
let envObject = null;
|
|
7261
7361
|
if (envLength) {
|
|
7262
7362
|
envObject = {};
|
|
@@ -7329,6 +7429,15 @@ export function init(RuntimeName, PHPLoader) {
|
|
|
7329
7429
|
PHPWASM.child_proc_by_fd[ProcInfo.stderrParentFd] = ProcInfo;
|
|
7330
7430
|
PHPWASM.child_proc_by_pid[ProcInfo.pid] = ProcInfo;
|
|
7331
7431
|
cp.on('exit', function (code) {
|
|
7432
|
+
for (const fd of [
|
|
7433
|
+
// The child process exited. Let's clean up its output streams:
|
|
7434
|
+
ProcInfo.stdoutChildFd,
|
|
7435
|
+
ProcInfo.stderrChildFd,
|
|
7436
|
+
]) {
|
|
7437
|
+
if (FS.streams[fd] && !FS.isClosed(FS.streams[fd])) {
|
|
7438
|
+
FS.close(FS.streams[fd]);
|
|
7439
|
+
}
|
|
7440
|
+
}
|
|
7332
7441
|
ProcInfo.exitCode = code;
|
|
7333
7442
|
ProcInfo.exited = true;
|
|
7334
7443
|
// Emit events for the wasm_poll_socket function.
|
|
@@ -7379,12 +7488,52 @@ export function init(RuntimeName, PHPLoader) {
|
|
|
7379
7488
|
* listen to the 'exit' event.
|
|
7380
7489
|
*/ try {
|
|
7381
7490
|
await new Promise((resolve, reject) => {
|
|
7382
|
-
|
|
7383
|
-
|
|
7491
|
+
/**
|
|
7492
|
+
* There was no `await` between the `spawnProcess` call
|
|
7493
|
+
* and the `await` below so the process haven't had a chance
|
|
7494
|
+
* to run any of the exit-related callbacks yet.
|
|
7495
|
+
*
|
|
7496
|
+
* Good.
|
|
7497
|
+
*
|
|
7498
|
+
* Let's listen to all the lifecycle events and resolve
|
|
7499
|
+
* the promise when the process starts or immediately crashes.
|
|
7500
|
+
*/ let resolved = false;
|
|
7501
|
+
cp.on('spawn', () => {
|
|
7502
|
+
if (resolved) return;
|
|
7503
|
+
resolved = true;
|
|
7504
|
+
resolve();
|
|
7505
|
+
});
|
|
7506
|
+
cp.on('error', (e) => {
|
|
7507
|
+
if (resolved) return;
|
|
7508
|
+
resolved = true;
|
|
7509
|
+
reject(e);
|
|
7510
|
+
});
|
|
7511
|
+
cp.on('exit', function (code) {
|
|
7512
|
+
if (resolved) return;
|
|
7513
|
+
resolved = true;
|
|
7514
|
+
if (code === 0) {
|
|
7515
|
+
resolve();
|
|
7516
|
+
} else {
|
|
7517
|
+
reject(
|
|
7518
|
+
new Error(`Process exited with code ${code}`)
|
|
7519
|
+
);
|
|
7520
|
+
}
|
|
7521
|
+
});
|
|
7522
|
+
/**
|
|
7523
|
+
* If the process haven't even started after 5 seconds, something
|
|
7524
|
+
* is wrong. Perhaps we're missing an event listener, or perhaps
|
|
7525
|
+
* the `spawnProcess` implementation failed to dispatch the relevant
|
|
7526
|
+
* event. Either way, let's crash to avoid blocking the proc_open()
|
|
7527
|
+
* call indefinitely.
|
|
7528
|
+
*/ setTimeout(() => {
|
|
7529
|
+
if (resolved) return;
|
|
7530
|
+
resolved = true;
|
|
7531
|
+
reject(new Error('Process timed out'));
|
|
7532
|
+
}, 5e3);
|
|
7384
7533
|
});
|
|
7385
7534
|
} catch (e) {
|
|
7386
7535
|
console.error(e);
|
|
7387
|
-
wakeUp(
|
|
7536
|
+
wakeUp(ProcInfo.pid);
|
|
7388
7537
|
return;
|
|
7389
7538
|
}
|
|
7390
7539
|
// Now we want to pass data from the STDIN source supplied by PHP
|
|
@@ -8277,14 +8426,7 @@ export function init(RuntimeName, PHPLoader) {
|
|
|
8277
8426
|
const POLLNVAL = 32;
|
|
8278
8427
|
return returnCallback((wakeUp) => {
|
|
8279
8428
|
const polls = [];
|
|
8280
|
-
if (socketd
|
|
8281
|
-
const procInfo = PHPWASM.child_proc_by_fd[socketd];
|
|
8282
|
-
if (procInfo.exited) {
|
|
8283
|
-
wakeUp(0);
|
|
8284
|
-
return;
|
|
8285
|
-
}
|
|
8286
|
-
polls.push(PHPWASM.awaitEvent(procInfo.stdout, 'data'));
|
|
8287
|
-
} else if (FS.isSocket(FS.getStream(socketd)?.node.mode)) {
|
|
8429
|
+
if (FS.isSocket(FS.getStream(socketd)?.node.mode)) {
|
|
8288
8430
|
const sock = getSocketFromFD(socketd);
|
|
8289
8431
|
if (!sock) {
|
|
8290
8432
|
wakeUp(0);
|
|
@@ -8318,7 +8460,12 @@ export function init(RuntimeName, PHPLoader) {
|
|
|
8318
8460
|
polls.push(PHPWASM.awaitConnection(ws));
|
|
8319
8461
|
lookingFor.add('POLLOUT');
|
|
8320
8462
|
}
|
|
8321
|
-
if (
|
|
8463
|
+
if (
|
|
8464
|
+
events & POLLHUP ||
|
|
8465
|
+
events & POLLIN ||
|
|
8466
|
+
events & POLLOUT ||
|
|
8467
|
+
events & POLLERR
|
|
8468
|
+
) {
|
|
8322
8469
|
polls.push(PHPWASM.awaitClose(ws));
|
|
8323
8470
|
lookingFor.add('POLLHUP');
|
|
8324
8471
|
}
|
|
@@ -8327,6 +8474,13 @@ export function init(RuntimeName, PHPLoader) {
|
|
|
8327
8474
|
lookingFor.add('POLLERR');
|
|
8328
8475
|
}
|
|
8329
8476
|
}
|
|
8477
|
+
} else if (socketd in PHPWASM.child_proc_by_fd) {
|
|
8478
|
+
const procInfo = PHPWASM.child_proc_by_fd[socketd];
|
|
8479
|
+
if (procInfo.exited) {
|
|
8480
|
+
wakeUp(0);
|
|
8481
|
+
return;
|
|
8482
|
+
}
|
|
8483
|
+
polls.push(PHPWASM.awaitEvent(procInfo.stdout, 'data'));
|
|
8330
8484
|
} else {
|
|
8331
8485
|
setTimeout(function () {
|
|
8332
8486
|
wakeUp(1);
|
|
@@ -8639,21 +8793,21 @@ export function init(RuntimeName, PHPLoader) {
|
|
|
8639
8793
|
a4
|
|
8640
8794
|
));
|
|
8641
8795
|
|
|
8642
|
-
var _wasm_add_cli_arg = (Module['_wasm_add_cli_arg'] = (a0) =>
|
|
8643
|
-
(_wasm_add_cli_arg = Module['_wasm_add_cli_arg'] = wasmExports['yb'])(
|
|
8644
|
-
a0
|
|
8645
|
-
));
|
|
8646
|
-
|
|
8647
|
-
var _run_cli = (Module['_run_cli'] = () =>
|
|
8648
|
-
(_run_cli = Module['_run_cli'] = wasmExports['zb'])());
|
|
8649
|
-
|
|
8650
8796
|
var _wasm_set_sapi_name = (Module['_wasm_set_sapi_name'] = (a0) =>
|
|
8651
8797
|
(_wasm_set_sapi_name = Module['_wasm_set_sapi_name'] =
|
|
8652
|
-
wasmExports['
|
|
8798
|
+
wasmExports['yb'])(a0));
|
|
8653
8799
|
|
|
8654
8800
|
var _wasm_set_phpini_path = (Module['_wasm_set_phpini_path'] = (a0) =>
|
|
8655
8801
|
(_wasm_set_phpini_path = Module['_wasm_set_phpini_path'] =
|
|
8656
|
-
wasmExports['
|
|
8802
|
+
wasmExports['zb'])(a0));
|
|
8803
|
+
|
|
8804
|
+
var _wasm_add_cli_arg = (Module['_wasm_add_cli_arg'] = (a0) =>
|
|
8805
|
+
(_wasm_add_cli_arg = Module['_wasm_add_cli_arg'] = wasmExports['Ab'])(
|
|
8806
|
+
a0
|
|
8807
|
+
));
|
|
8808
|
+
|
|
8809
|
+
var _run_cli = (Module['_run_cli'] = () =>
|
|
8810
|
+
(_run_cli = Module['_run_cli'] = wasmExports['Bb'])());
|
|
8657
8811
|
|
|
8658
8812
|
var _wasm_add_SERVER_entry = (Module['_wasm_add_SERVER_entry'] = (a0, a1) =>
|
|
8659
8813
|
(_wasm_add_SERVER_entry = Module['_wasm_add_SERVER_entry'] =
|