seanmorris / php-wasm

PHP in Browser, powered by WebAssembly.
https://seanmorris.github.io/php-wasm/
Apache License 2.0
606 stars 32 forks source link

Simple example #31

Closed uuf6429 closed 8 months ago

uuf6429 commented 11 months ago

I just spent half a day trying to get this to work.

Let's look at the documentation for a moment: https://github.com/seanmorris/php-wasm/blob/43b31b420452399a953978f6f4a864da9ac1db50/README.md?plain=1#L61 Awesome, I love easy installation.

Once the library is included in the page

Wait...what? Usage is simple....once you've installed and started using it????

ok, fine.. let's try some guess work... including the js file directly and...nothing. No errors, no wasm file in network and no alert. Fine, let's try the manual way. Oops, "require" is not a function...let's try the module approach with an external module/script...and nothing, again. No errors, no network calls, no popups, just nothing. Next point in the documentation is to use "your favourite bundler" to do set up the whole thing.....by the way, require() only works for bundlers or sever side js.

Well, the demo is definitely working and the documentation is mentioning an example, let's give that a look. oh wait, the example IS the demo. And it happens to be extremely unreadable, with random pieces of javascript for all the different demos in the sandbox.


Out of the various attempts, this is the simplest one I expected to see working:

<!DOCTYPE html>
<html lang="en">
    <head>
        <title>Test</title>
        <script src="./node_modules/php-wasm/php-web.js"></script>
    </head>
    <body>
        <script type="text/php">
        <?php vrzno_run('alert', ['Hello, world!']);
        </script>
    </body>
</html>

(ofc npm install php-wasm was executed in the same directory containing that html file) Copying php-web.js and php-web.wasm into the same directory and loading the script also didn't work.


In short:

  1. I don't know what I'm doing wrong, but it doesn't work
  2. Documentation is more deceptive than useful
  3. The only example I could find is the extremely convoluted sandbox demo
  4. Another point: the relation with oraoto/pib is weird and vague...who is actually owning this project? The project here says that it is a fork of oraoto/pib, but on the other repo it says this project was donated to it...and yet this is at v0.0.7 and the other one stuck in v0.0.4 from 2 years ago!?!?
seanmorris commented 8 months ago

@uuf6429 Sorry it took so long to get back. I've make some updates, this is the file you need to include now:

https://www.unpkg.com/php-wasm/php-tags.mjs

https://jsfiddle.net/d4hy3gv0/

<a href = "https://github.com/seanmorris/php-wasm">https://github.com/seanmorris/php-wasm</a>

<script type = "text/javascript" src = "https://www.unpkg.com/php-wasm/php-tags.mjs"></script>

<script type = "text/php">
<?php phpinfo();
</script>

I'll be updating the main docs soon, in the meantime, can you try that out?

uuf6429 commented 8 months ago

Apologies for the previous rant...I must have been pretty frustrated. 😅

I tried out that link and it didn't seem to work, but after a bit of time it worked - I'm guessing it takes time to download the runtime in the background.

That example pretty much answers my question, so I think this issue can be closed now. Thanks.