Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    Apr 2003
    Location
    Seoul, Korea
    Posts
    329
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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

  • #2
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,265
    Thanks
    6
    Thanked 48 Times in 48 Posts
    (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" 
         } 
    ?>


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •