-
Notifications
You must be signed in to change notification settings - Fork 278
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
manual PATH scanner instead of command #614
Conversation
command is not always available in shell_exec() see chrome-php#613 for details
My |
yeah i know what you mean😅 i have 25 here (WSL Ubuntu 24.04-beta) Benchmarking it on a AMD Ryzen 9 7950x (high-end 2022 system) Ubuntu 24.04-beta WSL:
(php does more work than command here because php does not bail, it simulates absolutely worst case scenario, command does not) doing the same on a Intel i7-8565U, a 2018 15watt low-power laptop cpu running on battery in power-saving mode, on WSL Ubuntu 24.04-beta: hans@DESKTOP-2LHJILI:~$ sudo bash -c 'sync; echo 3 > /proc/sys/vm/drop_caches';
hans@DESKTOP-2LHJILI:~$ time bash -c ' command -v google-chrome chromium-browser chrome chromium'
/usr/bin/chromium-browser
/snap/bin/chromium
real 0m0.820s
user 0m0.001s
sys 0m0.050s
hans@DESKTOP-2LHJILI:~$ time bash -c ' command -v google-chrome chromium-browser chrome chromium'
/usr/bin/chromium-browser
/snap/bin/chromium
real 0m0.476s
user 0m0.001s
sys 0m0.027s
hans@DESKTOP-2LHJILI:~$ sudo bash -c 'sync; echo 3 > /proc/sys/vm/drop_caches';
hans@DESKTOP-2LHJILI:~$ time php -r '
$a=explode(PATH_SEPARATOR, getenv("PATH"));
var_dump(count($a));
$names=["google-chrome","chromium-browser","chrome","chromium"];
foreach($a as $dir){
foreach($names as $name){
$file=$dir.DIRECTORY_SEPARATOR.$name;
if(file_exists($file) && is_executable($file)){
echo $file."\n";
}
}
}
';
int(32)
/usr/bin/chromium-browser
/bin/chromium-browser
/snap/bin/chromium
real 0m1.168s
user 0m0.062s
sys 0m0.076s
hans@DESKTOP-2LHJILI:~$ time php -r '
$a=explode(PATH_SEPARATOR, getenv("PATH"));
var_dump(count($a));
$names=["google-chrome","chromium-browser","chrome","chromium"];
foreach($a as $dir){
foreach($names as $name){
$file=$dir.DIRECTORY_SEPARATOR.$name;
if(file_exists($file) && is_executable($file)){
echo $file."\n";
}
}
}
';
int(32)
/usr/bin/chromium-browser
/bin/chromium-browser
/snap/bin/chromium
real 0m0.617s
user 0m0.030s
sys 0m0.030s 🤔 i think servers will do just fine. laptop users should specify chrome path to avoid the delay |
could be cached, but then we'd need to consider cache invalidation and cache poisoning 🤔 |
The performance will always be ok since Php already has the stat cache. It won't do anything in this case but it's still not an issue. |
I'm not really sure we should be making auto-discover that complicated. The point is to detect the most common places, only. I feel like people should be passing in the binary path explicitly, otherwise, or implementing this kind of logic in their own app. |
@GrahamCampbell so you're basically proposing
? |
I couldn't think of any better way to implement this and I recreating the |
I'm not going to go ahead with this. |
command is not always available in shell_exec() , observed on Ubuntu-24.04-beta + PHP8.3
see #613 for details