Closed kenorb closed 2 years ago
Sorry about that, looks like there's some vestigial code in there still. Can you try the following form, and let me know if it works for you?
php.run('<?php echo "Hello, world!";').then(retVal => {
// retVal contains the return code.
});
I've tried:
console.log(php.run('<?php echo "Hello, world!";').then(retVal => { console.log('retVal: ', retVal); }));
and retVal is zero now, but no sign of Hello text.
Results of console.log messages:
Promise {<pending>}
retVal: 0
Any additional suggestions how to return the echo'ed string?
You'll need a separate event listener to grab the output:
php.addEventListener('output', (event) => {
console.log(event.detail);
});
I know its a little awkward, but imagine sending code into the STDIN of a running PHP binary and grabbing the output from STDOUT. That's essentially what's going on under the hood here.
You might also want to wait for READY before you call RUN, this way you know the binary is downloaded and ready:
php.addEventListener('ready', () => {
php.run('<?php echo "Hello, world!";');
});
@kenorb are we able to close this issue?
Sure, the original issue has been solved. I'm going to do more testing as per suggestion. Update: Above suggestions works, thank you.
I'm trying to test PhpWeb inside NextJS, and it loads fine, but PhpWeb returns -1 error when running PHP code.
My code in brief:
I don't have any obvious errors, it's just PhpWeb instance returns code -1 (
{"returnValue": -1, "binary": {}}
).Are there any additional steps before running the code for the first time? Or any other way to debug the reason of the error?
I'm using the latest available version of php-wasm (
0.0.5
).