Skip to content
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

BUG: PHP binary check may report false negatives #3442

Open
1 task done
kdambekalns opened this issue Jan 28, 2025 · 1 comment
Open
1 task done

BUG: PHP binary check may report false negatives #3442

kdambekalns opened this issue Jan 28, 2025 · 1 comment
Labels

Comments

@kdambekalns
Copy link
Member

Is there an existing issue for this?

  • I have searched the existing issues

Current Behavior

With Xdebug enabled but no listener to connect to, the command used to check the PHP version and SAPI "fails".

$command[] = $phpCommand;
$command[] = <<<'EOF'
-r "echo json_encode(['sapi' => PHP_SAPI, 'version' => PHP_VERSION]);"
EOF;
$command[] = '2>&1'; // Output errors in response
exec(join(' ', $command), $output, $result);
$phpInformation = json_decode($output[0] ?? '{}', true) ?: [];
if ($result !== 0 || ($phpInformation['sapi'] ?? null) !== 'cli') {
throw new Exception\SubProcessException(sprintf('PHP binary might not exist or is not suitable for cli usage. Command `%s` didnt succeed.', $phpCommand), 1689676967447);
}

Because when Xdebug cannot connect, the output looks like this:

Xdebug: [Step Debug] Could not connect to debugging client. Tried: …:9003 (fallback through xdebug.client_host/xdebug.client_port).
{"sapi":"cli","version":"8.2.27"}

Note the expected JSON is now in the second line of the output (instead of $output[0]), so the check fails, even though $result is 0.

Expected Behavior

The Xdebug output is a warning, and, well hard to suppress, unfortunately. But it should not stop execution of the code… especially since warming up Flow from the CLI works just fine and also subsequent browser requests do work.

Steps To Reproduce

  1. Activate Xdebug, set xdebug.start_with_request=yes (as is default in DDEV)
  2. Do not listen for debug connections
  3. Call Flow from a browser, with empty Flow caches

Environment

- Flow: 8.3
- PHP: 8.3
- Xdebug: 3

Anything else?

  • A way to solve this would be to not redirect stderr to stdout? No, that Xdebug output is not sent to stderr.
  • Unset the subRequestEnvironmentVariables to get rid of XDEBUG_CONFIG? No, with xdebug.start_with_request=yes that doesn't help.
@mhsdesign
Copy link
Member

I thought at first that this is a regression of #3116

But originally the code looked like the following - also using the first line of the output. The only changes were that additionally to the version, the sapi type is also encoded.

exec($phpCommand . ' -r "echo PHP_VERSION;"', $output, $result);
if ($result !== 0) {
return;
}
$configuredPHPVersion = $output[0];
if (array_slice(explode('.', $configuredPHPVersion), 0, 2) !== array_slice(explode('.', PHP_VERSION), 0, 2)) {

I suspect we can expect all kinds of warnings in the first lines and read the output from behind expecting the last line to be truly the output. I dont know if that can ever fail too but should be a good fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants