From e926c03e77c974d3dfbd47b04cbebb3f4aaabb77 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 10 Nov 2025 18:30:39 +0000 Subject: [PATCH 1/4] Initial plan From c5179eb807ad8fab527a04ea32efc9caab0d4a66 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 10 Nov 2025 18:38:55 +0000 Subject: [PATCH 2/4] Add passthrough arguments support via -- separator Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com> --- features/server.feature | 7 +++++++ src/Server_Command.php | 40 ++++++++++++++++++++++++++++++++-------- 2 files changed, 39 insertions(+), 8 deletions(-) diff --git a/features/server.feature b/features/server.feature index 6317757..c538dec 100644 --- a/features/server.feature +++ b/features/server.feature @@ -15,3 +15,10 @@ Feature: Serve WordPress locally When I run `curl -sS localhost:8181/license.txt > /tmp/license.txt` And I run `cmp /tmp/license.txt license.txt` Then STDOUT should be empty + + Scenario: Passthrough arguments to PHP binary + Given a WP install + And I launch in the background `wp server --host=localhost --port=8182 -- -dmemory_limit=256M` + + When I run `curl -sS localhost:8182/wp-admin/install.php` + Then the return code should be 0 diff --git a/src/Server_Command.php b/src/Server_Command.php index 7b37992..47778c6 100644 --- a/src/Server_Command.php +++ b/src/Server_Command.php @@ -34,6 +34,10 @@ class Server_Command extends WP_CLI_Command { * [--config=] * : Configure the server with a specific .ini file. * + * [...] + * : Optional arguments to pass to the PHP binary. Any arguments after `--` + * will be passed through to the `php` command. + * * ## EXAMPLES * * # Make the instance available on any address (with port 8080) @@ -57,6 +61,13 @@ class Server_Command extends WP_CLI_Command { * Document root is / * Press Ctrl-C to quit. * + * # Pass extra parameters to the PHP binary + * $ wp server --docroot=public -- -dzend_extension=xdebug.so + * PHP 7.4.0 Development Server started at Wed Nov 10 18:00:00 2025 + * Listening on http://localhost:8080 + * Document root is /var/www/public + * Press Ctrl-C to quit. + * * @when before_wp_load */ public function __invoke( $_, $assoc_args ) { @@ -86,14 +97,27 @@ public function __invoke( $_, $assoc_args ) { if ( ! file_exists( $router_path ) ) { WP_CLI::error( "Couldn't find router.php" ); } - $cmd = Utils\esc_cmd( - '%s -S %s -t %s -c %s %s', - WP_CLI::get_php_binary(), - $assoc_args['host'] . ':' . $assoc_args['port'], - $docroot, - $assoc_args['config'], - Utils\extract_from_phar( $router_path ) - ); + + // Build the command with passthrough arguments + $cmd_format = '%s'; + $cmd_args = array( WP_CLI::get_php_binary() ); + + // Add passthrough arguments before the -S flag + if ( ! empty( $_ ) ) { + foreach ( $_ as $arg ) { + $cmd_format .= ' %s'; + $cmd_args[] = $arg; + } + } + + // Add the server flags + $cmd_format .= ' -S %s -t %s -c %s %s'; + $cmd_args[] = $assoc_args['host'] . ':' . $assoc_args['port']; + $cmd_args[] = $docroot; + $cmd_args[] = $assoc_args['config']; + $cmd_args[] = Utils\extract_from_phar( $router_path ); + + $cmd = Utils\esc_cmd( $cmd_format, ...$cmd_args ); $descriptors = array( STDIN, STDOUT, STDERR ); From 6d022b6fc249c469cb2acb4c74f02be3a50e7102 Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Mon, 10 Nov 2025 20:45:26 +0100 Subject: [PATCH 3/4] Lint fix --- src/Server_Command.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Server_Command.php b/src/Server_Command.php index 47778c6..81530b0 100644 --- a/src/Server_Command.php +++ b/src/Server_Command.php @@ -97,11 +97,11 @@ public function __invoke( $_, $assoc_args ) { if ( ! file_exists( $router_path ) ) { WP_CLI::error( "Couldn't find router.php" ); } - + // Build the command with passthrough arguments $cmd_format = '%s'; $cmd_args = array( WP_CLI::get_php_binary() ); - + // Add passthrough arguments before the -S flag if ( ! empty( $_ ) ) { foreach ( $_ as $arg ) { @@ -109,14 +109,14 @@ public function __invoke( $_, $assoc_args ) { $cmd_args[] = $arg; } } - + // Add the server flags $cmd_format .= ' -S %s -t %s -c %s %s'; $cmd_args[] = $assoc_args['host'] . ':' . $assoc_args['port']; $cmd_args[] = $docroot; $cmd_args[] = $assoc_args['config']; $cmd_args[] = Utils\extract_from_phar( $router_path ); - + $cmd = Utils\esc_cmd( $cmd_format, ...$cmd_args ); $descriptors = array( STDIN, STDOUT, STDERR ); From 558b46a9d93edad72c19ee101b4d5f2be50a68f8 Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Mon, 10 Nov 2025 21:53:18 +0100 Subject: [PATCH 4/4] Skip dashes --- src/Server_Command.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/Server_Command.php b/src/Server_Command.php index 81530b0..ec4ca0f 100644 --- a/src/Server_Command.php +++ b/src/Server_Command.php @@ -70,7 +70,7 @@ class Server_Command extends WP_CLI_Command { * * @when before_wp_load */ - public function __invoke( $_, $assoc_args ) { + public function __invoke( $args, $assoc_args ) { $defaults = array( 'host' => 'localhost', 'port' => 8080, @@ -103,8 +103,11 @@ public function __invoke( $_, $assoc_args ) { $cmd_args = array( WP_CLI::get_php_binary() ); // Add passthrough arguments before the -S flag - if ( ! empty( $_ ) ) { - foreach ( $_ as $arg ) { + if ( ! empty( $args ) ) { + foreach ( $args as $arg ) { + if ( '--' === $arg ) { + continue; + } $cmd_format .= ' %s'; $cmd_args[] = $arg; }