Skip to content

Commit c5179eb

Browse files
Copilotswissspidy
andcommitted
Add passthrough arguments support via -- separator
Co-authored-by: swissspidy <[email protected]>
1 parent e926c03 commit c5179eb

File tree

2 files changed

+39
-8
lines changed

2 files changed

+39
-8
lines changed

features/server.feature

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,10 @@ Feature: Serve WordPress locally
1515
When I run `curl -sS localhost:8181/license.txt > /tmp/license.txt`
1616
And I run `cmp /tmp/license.txt license.txt`
1717
Then STDOUT should be empty
18+
19+
Scenario: Passthrough arguments to PHP binary
20+
Given a WP install
21+
And I launch in the background `wp server --host=localhost --port=8182 -- -dmemory_limit=256M`
22+
23+
When I run `curl -sS localhost:8182/wp-admin/install.php`
24+
Then the return code should be 0

src/Server_Command.php

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -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,6 +61,13 @@ 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
6172
*/
6273
public function __invoke( $_, $assoc_args ) {
@@ -86,14 +97,27 @@ public function __invoke( $_, $assoc_args ) {
8697
if ( ! file_exists( $router_path ) ) {
8798
WP_CLI::error( "Couldn't find router.php" );
8899
}
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-
);
100+
101+
// Build the command with passthrough arguments
102+
$cmd_format = '%s';
103+
$cmd_args = array( WP_CLI::get_php_binary() );
104+
105+
// Add passthrough arguments before the -S flag
106+
if ( ! empty( $_ ) ) {
107+
foreach ( $_ as $arg ) {
108+
$cmd_format .= ' %s';
109+
$cmd_args[] = $arg;
110+
}
111+
}
112+
113+
// Add the server flags
114+
$cmd_format .= ' -S %s -t %s -c %s %s';
115+
$cmd_args[] = $assoc_args['host'] . ':' . $assoc_args['port'];
116+
$cmd_args[] = $docroot;
117+
$cmd_args[] = $assoc_args['config'];
118+
$cmd_args[] = Utils\extract_from_phar( $router_path );
119+
120+
$cmd = Utils\esc_cmd( $cmd_format, ...$cmd_args );
97121

98122
$descriptors = array( STDIN, STDOUT, STDERR );
99123

0 commit comments

Comments
 (0)