8000 [Process] Pass the commandline as array to `proc_open()` by ausi · Pull Request #52409 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Process] Pass the commandline as array to proc_open() #52409

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 21, 2023

Conversation

ausi
Copy link
Contributor
@ausi ausi commented Nov 1, 2023
Q A
Branch? 7.1
Bug fix? no
New feature? yes
Deprecations? no
Issues Fix #43162 (comment)
License MIT

Since PHP 7.4, proc_open() accepts an array which makes it twice as fast (4x as fast with PHP 8.3), see #43162 (comment)

This pull request enables calling proc_open() with an array if:

  1. $this->commandline is an array
  2. and we are not on Windows
  3. and PHP was compiled without --enable-sigchild

@ausi
Copy link
Contributor Author
ausi commented Nov 1, 2023

The failing unit test in PHP 8.3 seems to be a bug in PHP: php/php-src#12589

@OskarStark
Copy link
Contributor

It is a new feature and must therefore target 7.1 because of feature freeze period

Should we wait wait for a PHP bugfix before merge?

@OskarStark OskarStark modified the milestones: 6.4, 7.1 Nov 1, 2023
@carsonbot carsonbot changed the title Pass the commandline as array to proc_open() [Process] Pass the commandline as array to proc_open() Nov 1, 2023
@ausi ausi changed the base branch from 6.4 to 7.0 November 1, 2023 20:23
@ausi ausi requested a review from chalasr as a code owner November 1, 2023 20:23
@ausi ausi force-pushed the feature/proc-open-without-shell branch from 209588c to b56c0b0 Compare November 1, 2023 20:24
@ausi
Copy link
Contributor Author
ausi commented Nov 1, 2023

It is a new feature and must therefore target 7.1 because of feature freeze period

Changed the base to 7.0 (there is no 7.1 branch yet)

Should we wait wait for a PHP bugfix before merge?

I think so, yes.

@ausi
Copy link
Contributor Author
ausi commented Nov 3, 2023

Should we wait wait for a PHP bugfix before merge?

I think so, yes.

The PHP bug got closed, the new behavior is intended. I updated the pull request to handle that case.

@OskarStark OskarStark changed the title [Process] Pass the commandline as array to proc_open() [Process] Pass the commandline as array to proc_open() Nov 3, 2023
@ausi ausi force-pushed the feature/proc-open-without-shell branch from 4b31327 to 3eca0b9 Compare November 8, 2023 10:25
@ausi
Copy link
Contributor Author
ausi commented Nov 12, 2023

The PHP bug php/php-src#12589 got reopened, so we should wait until that was resolved there I think. 
UPDATE 2023-11-13: was closed again

@ausi ausi marked this pull request as draft November 12, 2023 11:50
@ausi ausi marked this pull request as ready for review November 13, 2023 08:36
@carsonbot carsonbot modified the milestones: 7.1, 7.0 Nov 13, 2023
@carsonbot
Copy link

Hey!

Thanks for your PR. You are targeting branch "7.0" but it seems your PR description refers to branch "7.1".
Could you update the PR description or change target branch? This helps core maintainers a lot.

Cheers!

Carsonbot

@ausi
Copy link
Contributor Author
ausi commented Nov 13, 2023

@carsonbot the 7.1 branch does not exist yet.

@OskarStark OskarStark modified the milestones: 7.0, 7.1 Nov 13, 2023
@ausi ausi changed the base branch from 7.0 to 7.1 November 16, 2023 09:45
Comment on lines 348 to 354
$process = @proc_open($commandline, $descriptors, $this->processPipes->pipes, $this->cwd, $envPairs, $this->options);
} finally {
restore_error_handler();
}

if (!\is_resource($process)) {
throw new RuntimeException('Unable to launch a new process.');
throw new RuntimeException('Unable to launch a new process: '.$lastError);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we throw a ProcessFailedException here? That would improve backwards compatibility I think.

Or should we maybe create a new exception like ProcessStartFailedException?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ProcessFailedException would be fine to me

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I created a new ProcessStartFailedException that extends the ProcessFailedException in 833bf1d.
This is a clean API I think and makes the changed behavior in PHP 8.3 a little bit more BC.

Copy link
Member
@nicolas-grekas nicolas-grekas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for working on this!
Can't we use an array on Windows also? Sorry I didn't read everything 😬
While at it, WDYT of the warnings on appveyor :)

'where' is not recognized as an internal or external command,
operable program or batch file.
'where' is not recognized as an internal or external command,
operable program or batch file.
ERROR: Invalid argument or option - '/usr/local/php/bin/php-invalid'.
Type "WHERE /?" for usage help.
ERROR: Invalid argument or option - '/usr/local/php/bin/php-invalid'.
Type "WHERE /?" for usage help.

Comment on lines 348 to 354
$process = @proc_open($commandline, $descriptors, $this->processPipes->pipes, $this->cwd, $envPairs, $this->options);
} finally {
restore_error_handler();
}

if (!\is_resource($process)) {
throw new RuntimeException('Unable to launch a new process.');
throw new RuntimeException('Unable to launch a new process: '.$lastError);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ProcessFailedException would be fine to me

@ausi ausi force-pushed the feature/proc-open-without-shell branch from d603793 to 833bf1d Compare November 20, 2023 15:53
@nicolas-grekas nicolas-grekas force-pushed the feature/proc-open-without-shell branch from 41770b7 to a300de8 Compare November 21, 2023 13:46
@nicolas-grekas
Copy link
Member

Thank you @ausi.

@nicolas-grekas nicolas-grekas merged commit e0de63d into symfony:7.1 Nov 21, 2023
@ausi
Copy link
Contributor Author
ausi commented Nov 22, 2023

Can't we use an array on Windows also?

I don’t think so as we use some heavy cmd.exe magic on Windows. Also, there would be no real difference on Windows I think as internally PHP just converts the array back into a string and sets bypass_shell = 1 which we also set.

crynobone added a commit to laravel/framework that referenced this pull request Jun 27, 2024
Introduced in symfony/symfony#52409 we no longer
should use `Illuminate\Support\ProcessUtils::escapeArgument()` unless
calling `Process` via `Process::fromShellCommandline()`

fixes #51820

Signed-off-by: Mior Muhammad Zaki <crynobone@gmail.com>
taylorotwell pushed a commit to laravel/framework that referenced this pull request Jun 27, 2024
Introduced in symfony/symfony#52409 we no longer
should use `Illuminate\Support\ProcessUtils::escapeArgument()` unless
calling `Process` via `Process::fromShellCommandline()`

fixes #51820

Signed-off-by: Mior Muhammad Zaki <crynobone@gmail.com>
taylorotwell pushed a commit to illuminate/support that referenced this pull request Jun 27, 2024
Introduced in symfony/symfony#52409 we no longer
should use `Illuminate\Support\ProcessUtils::escapeArgument()` unless
calling `Process` via `Process::fromShellCommandline()`

fixes #51820

Signed-off-by: Mior Muhammad Zaki <crynobone@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
892C
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Process] Allow running multiple commands at once
6 participants
0