@@ -34,6 +34,10 @@ class Server_Command extends WP_CLI_Command {
3434 * [--config=<file>]
3535 * : Configure the server with a specific .ini file.
3636 *
37+ * [<passthrough>...]
38+ * : Optional arguments to pass to the PHP binary. Any arguments after `--`
39+ * will be passed through to the `php` command.
40+ *
3741 * ## EXAMPLES
3842 *
3943 * # Make the instance available on any address (with port 8080)
@@ -57,9 +61,20 @@ class Server_Command extends WP_CLI_Command {
5761 * Document root is /
5862 * Press Ctrl-C to quit.
5963 *
64+ * # Pass extra parameters to the PHP binary
65+ * $ wp server --docroot=public -- -dzend_extension=xdebug.so
66+ * PHP 7.4.0 Development Server started at Wed Nov 10 18:00:00 2025
67+ * Listening on http://localhost:8080
68+ * Document root is /var/www/public
69+ * Press Ctrl-C to quit.
70+ *
6071 * @when before_wp_load
72+ *
73+ * @param array<string> $args Positional arguments passed through to the PHP binary.
74+ * @param array{host: string, port: string, docroot?: string, config?: string} $assoc_args Associative arguments passed to the command.
75+ * @return void
6176 */
62- public function __invoke ( $ _ , $ assoc_args ) {
77+ public function __invoke ( $ args , $ assoc_args ) {
6378 $ defaults = array (
6479 'host ' => 'localhost ' ,
6580 'port ' => 8080 ,
@@ -86,14 +101,25 @@ public function __invoke( $_, $assoc_args ) {
86101 if ( ! file_exists ( $ router_path ) ) {
87102 WP_CLI ::error ( "Couldn't find router.php " );
88103 }
89- $ cmd = Utils \esc_cmd (
90- '%s -S %s -t %s -c %s %s ' ,
91- WP_CLI ::get_php_binary (),
92- $ assoc_args ['host ' ] . ': ' . $ assoc_args ['port ' ],
93- $ docroot ,
94- $ assoc_args ['config ' ],
95- Utils \extract_from_phar ( $ router_path )
96- );
104+
105+ // Build the command with passthrough arguments
106+ $ cmd_format = '%s ' ;
107+ $ cmd_args = array ( WP_CLI ::get_php_binary () );
108+
109+ // Add passthrough arguments before the -S flag
110+ if ( ! empty ( $ args ) ) {
111+ $ cmd_format .= str_repeat ( ' %s ' , count ( $ args ) );
112+ $ cmd_args = array_merge ( $ cmd_args , $ args );
113+ }
114+
115+ // Add the server flags
116+ $ cmd_format .= ' -S %s -t %s -c %s %s ' ;
117+ $ cmd_args [] = $ assoc_args ['host ' ] . ': ' . $ assoc_args ['port ' ];
118+ $ cmd_args [] = $ docroot ;
119+ $ cmd_args [] = $ assoc_args ['config ' ];
120+ $ cmd_args [] = Utils \extract_from_phar ( $ router_path );
121+
122+ $ cmd = Utils \esc_cmd ( $ cmd_format , ...$ cmd_args );
97123
98124 $ descriptors = array ( STDIN , STDOUT , STDERR );
99125
0 commit comments