php-wasm
php-wasm copied to clipboard
Issues with PHP CGI Server.
Get a vague error message saying the request was denied etc using the demo / example..
hi, how do you setup PHP CGI? i was curious about it. I can see the demo of laravel etc, but dont know how to setup. thanks
@blackjyn - seek the documentation it should help you out.... If no luck - lmk.
on this one right? https://github.com/seanmorris/php-wasm/blob/master/demo-node
Assuming you are trying to run it in the web. This is the one you need - here
@MarketingPip Are you running the CGI servier in a browser or in nodejs?
@seanmorris - browser on incognito environment (storage issue?)
@seanmorris - browser on incognito environment (storage issue?)
What's the error you're getting?
@seanmorris - afk this weekend but my apologizes for not noting error earlier.
I do believe it was a "No response" or something error. I can confirm this by Monday etc.
I am getting these errors with the following js and webpack config
Register service worker:
if ('serviceWorker' in navigator) {
navigator.serviceWorker.register('/build/sw.js')
.then((registration) => {
console.log('Service Worker registered:', registration);
})
.catch((error) => {
console.error('Service Worker registration failed:', error);
});
}
sw.ts
/// <reference lib="WebWorker" />
import { PhpCgiWorker } from 'php-cgi-wasm/PhpCgiWorker';
declare const self: ServiceWorkerGlobalScope;
// Spawn the PHP-CGI binary
const php = new PhpCgiWorker({
prefix: '/php-wasm',
docroot: '/persist/www',
types: {
jpeg: 'image/jpeg',
jpg: 'image/jpeg',
gif: 'image/gif',
png: 'image/png',
svg: 'image/svg+xml',
},
});
// Set up the event handlers
self.addEventListener('install', (event) => php.handleInstallEvent(event));
self.addEventListener('activate', (event) => php.handleActivateEvent(event));
self.addEventListener('fetch', (event) => php.handleFetchEvent(event));
self.addEventListener('message', (event) => php.handleMessageEvent(event));
webpack config:
import path from 'path';
import { Configuration } from 'webpack';
const config: Configuration = {
entry: {
sw: './resources/js/sw.ts',
},
output: {
filename: '[name].js',
path: path.resolve(__dirname, 'public/build'),
},
resolve: {
extensions: ['.ts', '.tsx', '.js'],
alias: {
'@': path.resolve(__dirname, 'resources/js'),
},
},
module: {
rules: [
{
test: /\.(ts|js)x?$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
options: {
presets: ['@babel/preset-env', '@babel/preset-typescript'],
},
},
},
],
},
target: 'webworker',
mode: 'development',
devtool: 'source-map',
};
export default config;
@ZebTheWizard - refer to this here
I'm confused. The docs say I should be able to run php-cgi-wasm in the browser, but php-web-cgi.mjs clearly has a few references to XMLHttpRequest, and web workers do not have access to DOM APIs. My webpack config is based off of the webpack configuration here
Having a hard time compiling the example service worker.
I'm confused. The docs say I should be able to run php-cgi-wasm in the browser, but
php-web-cgi.mjsclearly has a few references toXMLHttpRequest, and web workers do not have access to DOM APIs. My webpack config is based off of the webpack configuration hereHaving a hard time compiling the example service worker.
It seems like I need to include webpack-dev-server in my webpack config to remove the errors.
However, now I cannot get a response when sending a message to the worker.
import { sendMessageFor, onMessage } from 'php-cgi-wasm/msg-bus';
navigator.serviceWorker.addEventListener('message', onMessage);
const sendMessage = sendMessageFor(location.origin + '/build/sw.js')
if ('serviceWorker' in navigator) {
navigator.serviceWorker.register('/build/sw.js')
.then((registration) => {
console.log('Service Worker registered:', registration.active);
sendMessage('readdir', ['/persist']).then(console.log).catch(console.error)
})
.catch((error) => {
console.error('Service Worker registration failed:', error);
});
}
@ZebTheWizard - I am not sure. Open a separate issue and maybe the creator of this repo will help you.
@ZebTheWizard - I am not sure. Open a separate issue and maybe the creator of this repo will help you.
Alright thanks, I've added a separate issue https://github.com/seanmorris/php-wasm/issues/77 since I'm trying to test a simple implementation of CGI web worker.
Seems like webpack-dev-server is required and I'm currently on version 0.0.9-alpha-27