Add timeout on unix agent execution after connect.

This commit is contained in:
Louis Rossouw
2015-06-21 19:36:44 +02:00
parent 62da1434f2
commit 9f36182b7d
+11 -1
View File
@@ -12,13 +12,23 @@ if ($device['os_group'] == "unix")
$agent_start = utime();
$agent = fsockopen($device['hostname'], $agent_port, $errno, $errstr, 10);
// Set stream timeout (for timeouts during agent fetch
stream_set_timeout($agent,10);
$agentinfo = stream_get_meta_data($agent);
if (!$agent)
{
echo "Connection to UNIX agent failed on port ".$port.".";
} else {
while (!feof($agent))
// fetch data while not eof and not timed-out
while ((!feof($agent)) && (!$agentinfo['timed_out']))
{
$agent_raw .= fgets($agent, 128);
$agentinfo = stream_get_meta_data($agent);
}
if ($agentinfo['timed_out'])
{
echo "Connection to UNIX agent timed out during fetch on port ".$port.".";
}
}