Skip to content

Commit

Permalink
PHP Show & Tell Fun
Browse files Browse the repository at this point in the history
  • Loading branch information
WebReflection committed Oct 3, 2023
1 parent 3ef41ed commit 67a743a
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
13 changes: 10 additions & 3 deletions esm/interpreter/php-wasm.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { dedent } from '../utils.js';
import { fetchFiles, fetchPaths, io, stdio, writeFileShim } from './_utils.js';
import { io, stdio } from './_utils.js';

const type = 'php-wasm';

Expand All @@ -11,10 +11,17 @@ export default {
type,
module: (version = '0.0.3') => `https://cdn.jsdelivr.net/npm/@webreflection/php@${version}/es.js`,
async engine({ PhpWeb }, _, url) {
const { stderr, stdout, get } = stdio();
const { stderr, get } = stdio();
const interpreter = await new Promise(resolve => {
let timer = 0, chunks = [];
const php = new PhpWeb({
print: stdout,
print: (message) => {
chunks.push(message);
clearTimeout(timer);
timer = setTimeout(() => {
document.getElementById('target').innerHTML = chunks.splice(0).join('');
});
},
printErr: (message) => {
if (message) stderr(message);
},
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,6 @@
"html-escaper": "^3.0.3"
},
"worker": {
"blob": "sha256-ixJNXrBnwM18zoc4l44JmnNzgD+eoNpGaOcZz3dXP94="
"blob": "sha256-BDFBL6yh1wOU5tFuRvJ/0Eg3QHPu/yDsay/B77CbrGM="
}
}
4 changes: 2 additions & 2 deletions test/php-wasm.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
</head>
<body>
<script type="php-wasm">
echo 'Hello PHP';
vrzno_run('alert', ['Hello, World!']);
phpinfo();
</script>
<div id="target"></div>
</body>
</html>

0 comments on commit 67a743a

Please sign in to comment.