Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions packages/php-wasm/node/src/test/php-worker.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,15 @@ describe('PHP Worker', () => {
}
}
);

it('addEventListener() should add a listener for all PHP instances spawned by the worker', async () => {
const received: any[] = [];
worker.addEventListener('runtime.beforeExit', (event) => {
received.push(event);
});
await worker.run({
code: `<?php echo getcwd();`,
});
expect(received).toHaveLength(1);
});
});
1 change: 1 addition & 0 deletions packages/php-wasm/universal/src/lib/php-worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ export class PHPWorker implements LimitedPHPApi, AsyncDisposable {
if (this.chroot !== null) {
php.chdir(this.chroot);
}
this.registerWorkerListeners(php);
return { php, reap };
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,6 @@ export class PlaygroundCliBlueprintV1Worker extends PHPWorker {
});
},
onPHPInstanceCreated: async (php) => {
this.registerWorkerListeners(php);
await mountResources(php, mountsBeforeWpInstall);
await mountResources(php, mountsAfterWpInstall);
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,6 @@ export class PlaygroundCliBlueprintV2Worker extends PHPWorker {
'openssl.cafile': '/internal/shared/ca-bundle.crt',
},
onPHPInstanceCreated: async (php: PHP) => {
this.registerWorkerListeners(php);
await mountResources(php, args['mount-before-install'] || []);
if (this.blueprintTargetResolved) {
await mountResources(php, args.mount || []);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,6 @@ export abstract class PlaygroundWorkerEndpoint extends PHPWorker {
if (withNetworking) {
await this.networkTransport!.setupMessageHandler(php);
}
this.registerWorkerListeners(php);
},
spawnHandler: sandboxedSpawnHandlerFactory,
sapiName,
Expand Down
Loading