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

[CMSP-791] Document changes to stderr in WP-CLI #8811

Merged
merged 5 commits into from
Jan 3, 2024
Merged
Changes from 4 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
59 changes: 58 additions & 1 deletion source/content/guides/wp-cli/07-wp-cli-troubleshoot.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,64 @@ ini_set('arg_separator.output', '&');

Actions or filters that require CLI tools like WP-CLI might fail from `wp-config.php`, because the functions required are not yet accessible. Put these directives in an [MU Plugin](/guides/wordpress-configurations/mu-plugin) to resolve this issue.

## Changes to WP-CLI on the Platform (January 15th 2024)

<Alert title="What's the TL;DR?" type="info" >
The appearance of PHP errors is changing when invoking WP-CLI. This is unlikely to affect you unless you have shell scripts that are specifically expecting to handle or parse PHP errors as part of the output of a WP-CLI command.
</Alert>

### Before January 15th
When a command is invoked in WP-CLI in a non-live environment, errors are sent to STDOUT as part of the output. When invoked over Terminus, errors are printed before the command output. In this example, I have called `trigger_error()` for a warning and notice in my `wp-config.php` file.
```bash
$ terminus wp <site>.<env> -- config get table_prefix

Notice: A Notice. in phar:///opt/pantheon/wpcli/wp-cli-2.8.1.phar/vendor/wp-cli/config-command/src/Config_Command.php(444) : eval()'d code on line 78

Warning: A Warning. in phar:///opt/pantheon/wpcli/wp-cli-2.8.1.phar/vendor/wp-cli/config-command/src/Config_Command.php(444) : eval()'d code on line 79
wp_
[notice] Command: <site>.<env> -- wp config get table_prefix [Exit: 0]
```

This makes it especially difficult to script something that relies on capturing the value of a given command (i.e. `config get` or `plugin list`), as the errors also end up captured, and it takes convoluted shell gymnastics to work around.
```bash
$ PREFIX=$(terminus remote:wp <site>.<env> -- config get table_prefix)
[notice] Command: <site>.<env> -- wp config get table_prefix [Exit: 0]
$ echo $PREFIX

Notice: A Notice. in phar:///opt/pantheon/wpcli/wp-cli-2.8.1.phar/vendor/wp-cli/config-command/src/Config_Command.php(444) : eval()'d code on line 78

Warning: A Warning. in phar:///opt/pantheon/wpcli/wp-cli-2.8.1.phar/vendor/wp-cli/config-command/src/Config_Command.php(444) : eval()'d code on line 79
wp_
```

### Starting January 15th
pwtyler marked this conversation as resolved.
Show resolved Hide resolved
When running WP-CLI, `display_errors` will be changed to `stderr` in `php.ini`, so that errors can be handled separate from the actual command output. Three changes are notable here:

#### Errors go to STDERR
The obvious and intentional change. With errors going to `stderr`, it is now possible to capture the output of a WP-CLI command with no extra steps.
```bash
$ PREFIX=$(terminus remote:wp <site>.<env> -- config get table_prefix)
Notice: A Notice. in phar:///opt/pantheon/wpcli/wp-cli-2.8.1.phar/vendor/wp-cli/config-command/src/Config_Command.php(444) : eval()'d code on line 78
Warning: A Warning. in phar:///opt/pantheon/wpcli/wp-cli-2.8.1.phar/vendor/wp-cli/config-command/src/Config_Command.php(444) : eval()'d code on line 79
[notice] Command: <site>.<env> -- wp config get table_prefix [Exit: 0]
$ echo $PREFIX
wp_
```

#### Live errors will display in WP-CLI
The change to WP-CLI’s error handling is environment-agnostic, so while `display_errors` remains `off` (i.e. unchanged) on Live PHP-FPM configuration (i.e. in the browser), it will be `stderr` only for CLI interactions.

#### Terminus now displays error messages after the command output
Because of Terminus’ specific handling of STDOUT and STDERR, PHP errors now display after the command output instead of before.
```bash
$ terminus remote:wp <site>.<env> -- config get table_prefix
wp_
Notice: A Notice. in phar:///opt/pantheon/wpcli/wp-cli-2.8.1.phar/vendor/wp-cli/config-command/src/Config_Command.php(444) : eval()'d code on line 78
Warning: A Warning. in phar:///opt/pantheon/wpcli/wp-cli-2.8.1.phar/vendor/wp-cli/config-command/src/Config_Command.php(444) : eval()'d code on line 79
[notice] Command: <site>.<env> -- wp config get table_prefix [Exit: 0]
```

## More Resources

- [Configure Your wp-config.php File](/guides/php/wp-config-php)
- [WordPress and PHP Sessions](/guides/php/wordpress-sessions)
- [WordPress and PHP Sessions](/guides/php/wordpress-sessions)
Loading