Skip to content

Commit 65426f4

Browse files
committed
Only bootstrap contents of /internal/shared once
1 parent b2e0a07 commit 65426f4

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

packages/php-wasm/compile/php/phpwasm-emscripten-library.js

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,19 +56,25 @@ const LibraryExample = {
5656

5757
// The files from the preload directory are preloaded using the
5858
// auto_prepend_file php.ini directive.
59-
FS.mkdir('/internal/shared/preload');
59+
FS.mkdirTree('/internal/shared/preload');
6060
// Platform-level bin directory for a fallback `php` binary. Without it,
6161
// PHP may not populate the PHP_BINARY constant.
62-
FS.mkdir('/internal/shared/bin');
62+
FS.mkdirTree('/internal/shared/bin');
6363
const originalOnRuntimeInitialized = Module['onRuntimeInitialized'];
6464
Module['onRuntimeInitialized'] = () => {
65-
// Dummy PHP binary for PHP to populate the PHP_BINARY constant.
66-
FS.writeFile(
65+
const { node: phpBinaryNode } = FS.lookupPath(
6766
'/internal/shared/bin/php',
68-
new TextEncoder().encode('#!/bin/sh\nphp "$@"')
67+
{ noent_okay: true },
6968
);
70-
// It must be executable to be used by PHP.
71-
FS.chmod('/internal/shared/bin/php', 0o755);
69+
if (!phpBinaryNode) {
70+
// Dummy PHP binary for PHP to populate the PHP_BINARY constant.
71+
FS.writeFile(
72+
'/internal/shared/bin/php',
73+
new TextEncoder().encode('#!/bin/sh\nphp "$@"')
74+
);
75+
// It must be executable to be used by PHP.
76+
FS.chmod('/internal/shared/bin/php', 0o755);
77+
}
7278
originalOnRuntimeInitialized();
7379
};
7480

0 commit comments

Comments
 (0)