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/8] 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/8] 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/8] 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/8] 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; } From 20d13ff1951c96926b5f8bfef084f2cc6d1fe41c Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 20 Feb 2026 13:02:59 +0000 Subject: [PATCH 5/8] Address review feedback: improve test, simplify loop, add PHPDoc params Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com> --- features/server.feature | 11 +++++++++-- src/Server_Command.php | 12 +++++------- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/features/server.feature b/features/server.feature index c538dec..1f1feb6 100644 --- a/features/server.feature +++ b/features/server.feature @@ -18,7 +18,14 @@ Feature: Serve WordPress locally Scenario: Passthrough arguments to PHP binary Given a WP install + And a file "mem.php" with: + """ + + """ 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 + When I run `curl -sS localhost:8182/mem.php` + Then STDOUT should be: + """ + 256M + """ diff --git a/src/Server_Command.php b/src/Server_Command.php index ec4ca0f..559488b 100644 --- a/src/Server_Command.php +++ b/src/Server_Command.php @@ -69,6 +69,9 @@ class Server_Command extends WP_CLI_Command { * Press Ctrl-C to quit. * * @when before_wp_load + * + * @param array $args Positional arguments passed through to the PHP binary. + * @param array $assoc_args Associative arguments passed to the command. */ public function __invoke( $args, $assoc_args ) { $defaults = array( @@ -104,13 +107,8 @@ public function __invoke( $args, $assoc_args ) { // Add passthrough arguments before the -S flag if ( ! empty( $args ) ) { - foreach ( $args as $arg ) { - if ( '--' === $arg ) { - continue; - } - $cmd_format .= ' %s'; - $cmd_args[] = $arg; - } + $cmd_format .= str_repeat( ' %s', count( $args ) ); + $cmd_args = array_merge( $cmd_args, $args ); } // Add the server flags From cefd4f1e15113156d5e9b5df7d8813a4d7dbfb5b Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Sun, 22 Feb 2026 20:47:13 +0100 Subject: [PATCH 6/8] PHPStan fixes --- phpstan.neon.dist | 3 --- src/Server_Command.php | 5 +++-- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/phpstan.neon.dist b/phpstan.neon.dist index 6fe826f..88efb15 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -8,6 +8,3 @@ parameters: scanFiles: - vendor/php-stubs/wordpress-stubs/wordpress-stubs.php treatPhpDocTypesAsCertain: false - ignoreErrors: - - identifier: missingType.parameter - - identifier: missingType.return diff --git a/src/Server_Command.php b/src/Server_Command.php index 559488b..2c2e350 100644 --- a/src/Server_Command.php +++ b/src/Server_Command.php @@ -70,8 +70,9 @@ class Server_Command extends WP_CLI_Command { * * @when before_wp_load * - * @param array $args Positional arguments passed through to the PHP binary. - * @param array $assoc_args Associative arguments passed to the command. + * @param array $args Positional arguments passed through to the PHP binary. + * @param array{host: string, port: string, docroot?: string, config?: string} $assoc_args Associative arguments passed to the command. + * @return void */ public function __invoke( $args, $assoc_args ) { $defaults = array( From 38c8b9880636a4aff42ebfc66dc92539e23b2c09 Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Sun, 22 Feb 2026 20:50:07 +0100 Subject: [PATCH 7/8] Fix test --- features/server.feature | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/features/server.feature b/features/server.feature index a88f6c3..8270ba9 100644 --- a/features/server.feature +++ b/features/server.feature @@ -18,7 +18,7 @@ Feature: Serve WordPress locally Scenario: Passthrough arguments to PHP binary Given a WP install - And a file "mem.php" with: + And a mem.php file: """ """ From 820f66679ce529669b8cce28cd07c57a330a3fda Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 12 Mar 2026 13:17:41 +0000 Subject: [PATCH 8/8] Remove outdated PHP 5.4 version check, update feature tag to php-7.2 Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com> --- features/server.feature | 2 +- server-command.php | 13 +------------ 2 files changed, 2 insertions(+), 13 deletions(-) diff --git a/features/server.feature b/features/server.feature index 8270ba9..4a47a73 100644 --- a/features/server.feature +++ b/features/server.feature @@ -1,4 +1,4 @@ -@require-php-5.4 +@require-php-7.2 Feature: Serve WordPress locally Scenario: Vanilla install diff --git a/server-command.php b/server-command.php index 6a0b018..8cd9e4e 100644 --- a/server-command.php +++ b/server-command.php @@ -9,15 +9,4 @@ require_once $wpcli_server_autoloader; } -WP_CLI::add_command( - 'server', - 'Server_Command', - array( - 'before_invoke' => function () { - $min_version = '5.4'; - if ( version_compare( PHP_VERSION, $min_version, '<' ) ) { - WP_CLI::error( "The `wp server` command requires PHP {$min_version} or newer." ); - } - }, - ) -); +WP_CLI::add_command( 'server', 'Server_Command' );