Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 09-13-2003, 10:21 AM   PM User | #1
joonstar
Regular Coder

 
Join Date: Apr 2003
Location: Seoul, Korea
Posts: 329
Thanks: 0
Thanked 0 Times in 0 Posts
joonstar is an unknown quantity at this point
checking the target server is on or off

<?php
$read = @fopen("http://220.89.242.117:8500","r" );

if (!$read){
header('Location: sorry.php');
}
else{
fclose($read);
header('Location: http://220.89.242.117:8500');
}
?>

The above code is intended for nex two conditions.

If the remote target server is dead, go to sorry.php.
If the remote target server is alive, go to the server.



But the result of the above code is;

(1) when the target server is off, the check page try to find the target
server for a long time, and it finally says it can't find the target server.

(2) when the target server is on the way of booting, the check page goes to
sorry page.

(3) when the target server is fully booted, the check page goes to the
target server page.

The problem happens when the target server is off.
Do you have more correct code for it?

Thanks in Advance
joonstar is offline   Reply With Quote
Old 09-13-2003, 01:35 PM   PM User | #2
Nightfire
Senior Coder

 
Nightfire's Avatar
 
Join Date: Jun 2002
Posts: 4,266
Thanks: 6
Thanked 48 Times in 48 Posts
Nightfire is on a distinguished road
(2) when the target server is on the way of booting, the check page goes to sorry page.

There's no way to detect if the server is online if the server isn't connected to the net yet. It will always go to the sorry page



Try this code

PHP Code:
<?php 
//Autor: Antonio Leal Elizondo 12/Ago/03 
//e-mail: [email]invasor@hotmail.com[/email] 
// This script pings a machine and checks if it's alive or not. 
// It can run a command in case the machine is not answering 

// Variables 
//------------------------- 
   
$unix      =  1//Put 1 here if you are using a UNIX machine 
   
$windows   =  0//Put 1 here if you are using a Windown machine 


   
$unix = (bool) $unix
   
$win  = (bool)  $windows

   
$count3;                            // Number of times to ping 
   
$host   "177.17.31.165";             // IP of the remote server 
   
$find "Tiempo de espera agotado";   // String to look for 
   
$shell"pwd";                          // Command to execute if the machine does not answer. 
   
$findUnix="0 packets received"


      
// Replaced nonvalued characters       
      
$hostpreg_replace ("/[^A-Za-z0-9.]/","",$host); 
      echo(
"Resultados: "); 
         
      
//Check the IP 
      
if ($unix==1){ 
         
$comm="ping -t $count $host"
         
$res=shell_exec($comm); 
      }else{ 
         
$comm="ping -n $count $host"
         
$res=shell_exec($comm); 
      } 
      
//  system("killall ping");// Kill all pings in case they exist. 
      //echo $res; 

      
$flagstrstr($res,$findUnix); 
      
$long=strlen($flag); 
     if (
$long<>0){ 
       echo 
"\n An error has occured at $host\n "
       echo   
date("D F Y  h:i a"); 
       echo 
"\n Executng auxiliary command \n "
       
$res=shell_exec($shell); 
        echo 
$res
      }else{ 
       echo 
"\n There are no problems with $host \n"
      echo   
date("D F Y  h:i a"). "\n" 
     } 
?>
__________________
Blue Panda
Website Design | 1 Pound Ads | 'ow much? | Coding Geeks
Nightfire is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 04:53 PM.


Advertisement
Log in to turn off these ads.