function validUrl($url) { if (filter_var($url, FILTER_VALIDATE_URL)) { $components = parse_url($url); // enable caching static $urlCache = []; $cacheKey = $components['scheme'] . $components['host'] . @$components['port']; if (isset($urlCache[$cacheKey])) { echo "Returning response for {$url} from cache." . PHP_EOL; return $urlCache[$cacheKey]; } $live = pingPort($components['host'], $components['scheme'], @$components['port']); $urlCache[$cacheKey] = $live; if ($live) { return true; } echo "Url {$url} is not live." . PHP_EOL; } return false; }
$Return['success'] = true; $Return['date_start'] = date("Y-m-d H:i:s"); $nRecno = 0; while ($row = $result->fetch_assoc()) { $time = explode(" ", microtime()); $startCheck = $time[1] + $time[0]; $Ports = explode(",", $row["port"]); $cHost = $row['host']; //echo " host: " . $cHost; $IsOn = 0; $Today = date("Y-m-d H:i:s"); $Lastlog = ''; foreach ($Ports as $key => $port) { $time = explode(" ", microtime()); $startping = $time[1] + $time[0]; $IsPing = pingPort($cHost, $port, $defaultValues["TimeOut"]); $time = explode(" ", microtime()); $totaltime = $time[1] + $time[0] - $startping; $Return["data"][$cHost]["port"]["{$port}"] = $IsPing; $IsOn += $IsPing ? 1 : 0; $Lastlog .= ($Lastlog == "" ? '' : ',') . $port . ':' . ($IsPing ? 'On' : 'Off'); //echo '['.$port. ':'.($IsPing? '<font color="green">On</font>':'<font color="red">Off</font>').'] '; $Sql = "INSERT INTO host_status (host,port,result,date,duration) " . " VALUES ('" . $row["ref"] . "' , '" . $port . "' , '" . $IsPing . "' , '" . $Today . "' ,'" . $totaltime . "')"; $dbconnect->query($Sql); } $Sql = "UPDATE host_detail SET lastcheck = now(), laststatus={$IsOn} " . ", lastlog='" . $Lastlog . "' WHERE host='{$cHost}' "; $dbconnect->query($Sql); $time = explode(" ", microtime()); $totaltime = $time[1] + $time[0] - $startCheck; $Return["data"][$row['host']]['timeused'] = $totaltime; // echo ' ',number_format($totaltime,2)." Secs. <br>";