Skip to content

[PHP] Tolerate pre-existing /internal directory when initializing the PHP module #2356

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: trunk
Choose a base branch
from
Draft
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
17 changes: 13 additions & 4 deletions packages/php-wasm/compile/php/phpwasm-emscripten-library.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,28 @@ const LibraryExample = {
.filter(Boolean)
.join(':');

// In multi-worker setups, some of the directories may already exist.
// Let's handle that gracefully.
function mkdirIfMissing(path) {
try {
FS.mkdir(path);
} catch (e) {
if (e.errno != ERRNO_CODES.EEXIST) throw e;
}
}
// The /internal directory is required by the C module. It's where the
// stdout, stderr, and headers information are written for the JavaScript
// code to read later on.
FS.mkdir('/internal');
mkdirIfMissing('/internal');
// The files from the shared directory are shared between all the
// PHP processes managed by PHPProcessManager.
FS.mkdir('/internal/shared');
mkdirIfMissing('/internal/shared');
// The files from the preload directory are preloaded using the
// auto_prepend_file php.ini directive.
FS.mkdir('/internal/shared/preload');
mkdirIfMissing('/internal/shared/preload');
// Platform-level bin directory for a fallback `php` binary. Without it,
// PHP may not populate the PHP_BINARY constant.
FS.mkdir('/internal/shared/bin');
mkdirIfMissing('/internal/shared/bin');
const originalOnRuntimeInitialized = Module['onRuntimeInitialized'];
Module['onRuntimeInitialized'] = () => {
// Dummy PHP binary for PHP to populate the PHP_BINARY constant.
Expand Down
3 changes: 0 additions & 3 deletions packages/php-wasm/universal/src/lib/load-php-runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,6 @@ export async function loadPHPRuntime(

const id = ++lastRuntimeId;

// TODO: Ask @adamziel why this is here.
// eslint-disable-next-line @typescript-eslint/no-unused-expressions -- why is this here?
PHPRuntime.FS;
PHPRuntime.id = id;
PHPRuntime.originalExit = PHPRuntime._exit;

Expand Down