Skip to content
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

[Breaking] Refactor PHP.ini management, remove php.setPhpIniPath() and php.setPhpIniEntry() #1423

Merged
merged 10 commits into from
May 20, 2024

Conversation

adamziel
Copy link
Collaborator

@adamziel adamziel commented May 17, 2024

What is this PR doing?

Refactors PHP.ini management:

  • Removes the php.setPhpIniEntry() methods that only worked correctly when called before initializing the PHP runtime.
  • Hardcodes the php.ini path to /internal/shared/php.ini. The developer is welcome to override that file as needed, but they can't customize the path. Once changing the path becomes important, let's add that feature at the Boot Protocol level.
  • Provides getPhpIniEntries(), setPhpIniEntries(), and withPHPIniValues() helpers that work at any point of the PHP runtime lifecycle.
  • Moves a list of the default php.ini values from php_wasm.c to base-php.ts where it can be customized without rebuilding the wasm module.

What problem is it solving?

Working with php.ini is highly problematic as you could never be sure whether your setPhpIni* call would be effective. Then, at the API level, the setPhpIni* methods were also excluded from some TypeScript types but not from the others.

Remaining work

  • Rebuild all the PHP modules

Testing Instructions

Confirm the CI tests pass.

@adamziel adamziel requested a review from a team as a code owner May 17, 2024 14:20
@adamziel adamziel changed the title Refactor PHP.ini management, remove php.setPhpIniPath() and php.setPhpIniEntry() [Breaking] Refactor PHP.ini management, remove php.setPhpIniPath() and php.setPhpIniEntry() May 17, 2024
@adamziel adamziel mentioned this pull request May 17, 2024
adamziel added a commit that referenced this pull request May 18, 2024
…ld (without the SQLite integration plugin)

Uses Playground CLI to produce a minified WordPress build, replacing the custom bash-based WordPress installation flow that relied on wget, unzip, sed, wp-cli etc.

This is to dogfood Playground CLI and put the boot protocol to a practical use. With this PR, CLI Playground produces a minified WordPress version that is later used to boot the web Playground.

Depends on #1423 #1423 #1425

 ## Testing instructions

Rebuild the latest WordPress with

```shell
rm -rf packages/playground/wordpress-builds/public/wp-6.5
npx nx bundle-wordpress:major-and-beta playground-wordpress-builds
```

Then run npm run dev and confirm the local Playground loads without any issues.

Related: #1398
adamziel added a commit that referenced this pull request May 18, 2024
Replaces a series of custom steps meant to unzip and configure WordPress with passinf the build zip as a preferredVersion.

To test, go to the WordPress PR previewer locally and try previewing one of the recent PRs. Confirm the installed WordPress versions is indeed not the latest stable.

Do not merge until these PRs are merged:

* #1423 
* #1424 
* #1425 
* #1426 
* #1427
Copy link
Collaborator

@bgrgicak bgrgicak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left a few comments, but it looks really good otherwise.

await php.writeFile(PHP_INI_PATH, stringify(ini));
}

export async function withPHPIniValues(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could use some comments. The name didn't make it clear to me that this runs a single callback with a set of custom PHP ini values.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call! I'll document that in a follow-up PR.

@@ -82,12 +82,8 @@ export async function preloadRequiredMuPlugin(php: UniversalPHP) {
?>`,
configureErrorLogging: `<?php
$log_file = WP_CONTENT_DIR . '/debug.log';
error_reporting(E_ALL);
define('ERROR_LOG_FILE', $log_file);
ini_set('error_log', $log_file);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we leaving this ini_set here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sold on storing logs in /wordpress/wp-content/debug.log by default. This choice affects a local mount and may not exist before WordPress is installed. I'm not sure what to do with this yet.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This choice affects a local mount and may not exist before WordPress is installed.

Let's move it to internals. Others can always override it.

);

if (!this.fileExists(PHP_INI_PATH)) {
this.writeFile(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why don't we use setPhpIniEntries here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because PHP_INI_PATH does not exist yet and setPhpIniEntries would fail. We could perhaps change setPhpIniEntries semantics to "create the file if it's missing", but this feels off – I want BasePHP to guarantee the file will be there later on and get a clear error if it isn't found at a later stage.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And if we ever want to do type-checking of known PHP ini settings, we could just write the blank file, and use setPhpIniEntries to write those initial settings.

@adamziel adamziel merged commit 100bfe5 into trunk May 20, 2024
5 checks passed
@adamziel adamziel deleted the remove-php-set-php-ini-entry branch May 20, 2024 08:18
adamziel added a commit that referenced this pull request May 20, 2024
## What is this PR doing?

Documents the php.ini-related functions introduced in
#1423.

Also, ensures `withPHPIniValues()` returns the return value of the
callback.

cc @bgrgicak 

## Testing Instructions

Confirm the CI checks pass.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants