I am having trouble when try to set timeout for my ssh2_exec
connection in PHP, so that when there is something wrong when running the command, it will release the executing thread and will not jam the whole web site. I have tried stream_set_timeout($stream,$seconds)
but it seems not to work as expected.
Is there any ideas on this?
//run specified command (ssh)
function runCMD($cmd){
if (!($stream = ssh2_exec($this->conn, $cmd )))
{
echo "fail: unable to execute command\n";
fclose($stream);
return ERROR_SSH_EXEC_COMM;
}
sleep(1);
stream_set_timeout($stream,5);//>>not work
stream_set_blocking($stream, true);
$res = stream_get_contents($stream);
return $res;
}