How is it best way to manage timeout on shell_exec() within a php loop?
I have tried to add timeout 10
in front of the command, but it breaks the entire loop in the first failure. I'm expecting every command can only executed at most 10 seconds within 10 loop cycling and return data on successfull.
<?php
function ShellC($params) {
$n = 0;
foreach ($params as $param) {
if ( ++$n < 11 ) {
$data = shell_exec('timeout 10 command_execute_param 2>/dev/null');
if ( !empty($data) ) {
return $data;
}
}
}
return false;
}
Thank you for your help!