I want to be able to get a response from a mail server that i dont have access to to find out if the server is up or down or the availability of the mail service
i was attempting to use the below code to get a response from the server in order to figure out its timeouts
Code: Select all
$host='apex-solutions.com';
$timeout=2;
//Open the socket
$handle=fsockopen('ddp://'.$host, 25, $errno, $errstr, $timeout);
if (!$handle)
echo "$errstr ($errno)<br>\r\n";
else {
//Set read timeout
stream_set_timeout($handle, $timeout);
for($i=0;$i<3;$i++){
//Time the responce
list($usec, $sec) = explode(" ", microtime(true));
$start=(float)$usec + (float)$sec;
//send somthing
$write=fwrite($handle,"echo this\n");
if(!$write){
echo "Error in writing to socked<br>\r\n";
break;
}
echo 'Send packet to '.$host;
//Try to read. the server will most likely respond with a "ICMP Destination Unreachable" and end the read. But that is a responce!
fread($handle,1024);
//Work out if we got a responce and time it
list($usec, $sec) = explode(" ", microtime(true));
$laptime=((float)$usec + (float)$sec)-$start;
if($laptime>$timeout)
echo " : No reply<br>\r\n";
else
echo " : Round trip = ".round($laptime,3)." s<br>\r\n";
}
fclose($handle);
}i am also using the below command to ping the serverWarning: fsockopen(): php_network_getaddresses: getaddrinfo failed: Name or service not known in /home/virtual/site15/fst/var/www/html/ping.php on line 9
Warning: fsockopen(): unable to connect to ddp://apex-solutions.com:25 in /home/virtual/site15/fst/var/www/html/ping.php on line 9
Success (0)
Code: Select all
// ping some server five times and store output in array $output
exec("tracert 66.227.2.83", $output,$status);
// format each line of output
if($status){
echo 'status '.$status.'<br>';
echo 'output '.$output[2].'<br>';
while(list(,$val) = each($output)){
echo 'ok';
echo "<p>".$key.' - '.$val."</p>";
}
}else{
echo 'failed';
}y am i not getting an outputstatus 127
output
Kendall