Skip to content

Instantly share code, notes, and snippets.

@MrVibe
Created April 13, 2017 13:21
Show Gist options
  • Save MrVibe/474651dd335d983e24773f16797a6457 to your computer and use it in GitHub Desktop.
Save MrVibe/474651dd335d983e24773f16797a6457 to your computer and use it in GitHub Desktop.
Ping Test from Server to another Server/Host/Ip address
<h1>Ping test from vibethemes server</h1>
<?php
$host = $_GET['host'];
if(empty($host)){die();}
if(strlen($host) > 50){die();}
set_error_handler(function($errno, $errstr, $errfile, $errline, array $errcontext) {
if (0 === error_reporting()) {
return false;
}
throw new ErrorException($errstr, 0, $errno, $errfile, $errline);
});
try {
$port = 80; $errCode ='';$errStr ='';
$waitTimeoutInSeconds = 1;
if($fp = fsockopen($host,$port,$errCode,$errStr,$waitTimeoutInSeconds)){
echo 'Ping Status to '.$host.' was : <span style="color:green">SUCCESSFUL</span>';
} else {
echo 'Ping Status to '.$host.' was : <span style="color:red">UNSUCCESSFUL</span>';
}
fclose($fp);
}catch (Exception $e) {
echo 'Ping Status to '.$host.' was : <span style="color:red">UNSUCCESSFUL</span>';
}
restore_error_handler();
die();
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment