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..ec4ca0f 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,9 +61,16 @@ 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 ) { + public function __invoke( $args, $assoc_args ) { $defaults = array( 'host' => 'localhost', 'port' => 8080, @@ -86,14 +97,30 @@ 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( $args ) ) { + foreach ( $args as $arg ) { + if ( '--' === $arg ) { + continue; + } + $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 );