seanmorris / php-wasm

PHP in Browser, powered by WebAssembly.
https://php-wasm.seanmorr.is/
Apache License 2.0
766 stars 40 forks source link

documentation or examples lacking..? how to get server-side content from the server into the client-side php..? #54

Open davidbuzz opened 2 months ago

davidbuzz commented 2 months ago

eg, presuming your "normal" server-side php queries a mysql database and emits the result as json or html fragments or whatever, when the php itself is moved to-the-browser, how does the php now get the "dynamic" part of the data from the database, or from the server endpoint.?

becasue of http same-site security, the client-side php can't be arbitrarily reaching-acoss the network to anything other than the server-from-which it was delivered, and so it either needs to use long-polling or websockets to get that data, or php-wasm-cgi forwards the call up-stream to the server that delivered the http request in the first place...?

an example of this sort of dynamic constent is the entire reason php is on the "server" these days, so being unable to do it is massive thorn in the value it offers by putting it in-the-browser.

seanmorris commented 1 week ago

@davidbuzz I just pushed out an update to Vrzno that enables url_fopen, so you should just be able to call $data = file_get_contents("https://YOUR_URL_HERE"); to pull data from a remote server. So long as CORS is enabled, it should work just like regular url_fopen. It runs a fetch() based GET request in the background.

Edit: example here: https://codepen.io/SeanMorris227/pen/poMRoyN?editors=1000

blackjyn commented 1 week ago

thanks @seanmorris . Im trying yoru sample locally , working just fine with :

<script async type = "module" src = "https://cdn.jsdelivr.net/npm/php-wasm@0.0.9-alpha-20/php-tags.mjs"></script>

but NOT with

<script async type="module" src="node_modules/php-wasm/php-tags.mjs"></script>

I updated the deps to php-wasm@0.0.9-alpha-20 , but didn't work