chrome-php / chrome

Instrument headless chrome/chromium instances from PHP
MIT License
2.28k stars 278 forks source link

command not (always?) available in shell_exec #613

Open divinity76 opened 8 months ago

divinity76 commented 8 months ago

testing with php8.3 on ubuntu24.04-beta, command is not available in shell_exec:

hans@DESKTOP-EE15SLU:~/projects/headless-chomium-recorder$ command -v google-chrome chromium-browser chrome chromium
/usr/bin/chromium-browser
/snap/bin/chromium
hans@DESKTOP-EE15SLU:~/projects/headless-chomium-recorder$ php -r 'var_dump(shell_exec("command -v google-chrome chromium-browser chrome chromium"));'
Command line code:1:
NULL
hans@DESKTOP-EE15SLU:~/projects/headless-chomium-recorder$ php -r 'var_dump(shell_exec("bash -c '\''command -v google-chrome chromium-browser chr
ome chromium'\''"));'
Command line code:1:
string(45) "/usr/bin/chromium-browser
/snap/bin/chromium
"
hans@DESKTOP-EE15SLU:~/projects/headless-chomium-recorder$ php -r 'var_dump(shell_exec("which google-chrome chromium-browser chrome chromium"));'
Command line code:1:
string(45) "/usr/bin/chromium-browser
/snap/bin/chromium
"
hans@DESKTOP-EE15SLU:~/projects/headless-chomium-recorder$ 

PHP8.3 migrated some execution commands from fork+exec to posix_spawn, this might be another side-effect?

either way, seems our alternatives are to migrate to type (...) or bash -c 'command -v (...)' or implement our own getenv("PATH")-scanner (or just find one in composer) 🤔

this breaks chrome/chromium path autodetect in BrowserFactory

divinity76 commented 8 months ago

proposed fix: https://github.com/chrome-php/chrome/pull/614 (manual PATH scanner)