Sponsored by NuSphere - PHP Software for PHP Application Developers - On Sale This Week for $100



Go Back   PHP-Editors > Programming Help > PHP Programming Help

PHP Programming Help Post any question relating to PHP Programming here and hopefully someone can help.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 2004-01-04, 02:28 PM
burrito
Guest
 
Posts: n/a
Default

PHP Code:

<?php
&#036;fp = @fsockopen('69.12.51.247',27015,$errno,$errstr,1);
if(&#33;$fp){
    
echo &#39;Down; // server is down
}else{
    echo &
#39;Up; // server is up
    
exit;
}
?>
Okay the script returns no error but, the server is up and the script says its down help please?
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 2004-01-06, 02:00 PM
Eric
Guest
 
Posts: n/a
Default

You can use this program or just alter it...

Code:
<?php
// Script created by telefoontoestel
// for info of some kind please send an email to
// telefoontoestel at officexpert dot digitaal dot biz

// get_microtime() function copied from php.net: function microtime() user contributes

// get_microtime function
function get_microtime(){
  list($usec, $sec) = @split(" ", microtime());
  return ((float)$usec + (float)$sec);
}
// end of get_microtime function

// ping function
function ping($server, $num_pings=4, $size=32, $time_out=15){
  if(!is_int($num_pings) || $num_pings < 0) $num_pings = 4;
  if(!is_int($size) || $size < 0) $size = 32;
  if(!is_int($time_out) || $time_out < 0) $time_out = 15;
  
  $results = Array();
  
  
  for($i = 0; $i < $size; $i++){
    $data .= "\0";
  }
  
  $server_ip = gethostbyname($server);
  $server_name = $server;
  
  if($server_ip != $server_name) $results[0]["server_name"] = $server_name." [".$server_ip."]";
  else $results[0]["server_name"] = $server_ip;
  $results[0]["server_ip"] = $server_ip;
  $results[0]["bytes"] = $size;
  
  
  
  for($i = 1; $i <= $num_pings; $i++){
    $start_timer = get_microtime();
    if(($handle = @fsockopen("udp://".$server_ip, 7, $errno, $errstr, $time_out)) == false)
      if(($handle = @fsockopen($server_ip, 7, $errno, $errstr, $time_out)) == false){
        $results[$i]["bytes"] == 0;
        $results[$i]["time"] == -1;
        continue;
      }
        
    @fputs($handle, $data, $size);
    $results[$i]["bytes"] = @fgets($handle, $size);
    $results[$i]["time"] = round((get_microtime() - $start_timer) * 1000);
    $start_timer = 0;
    @fclose($handle);
  }
  return $results;
}

// end of ping function

if(($server = $_GET["server"]) == "") $server = "127.0.0.1";

$result = ping($server);

$lost = 0;
$received = 0;
$send = sizeof($result) - 1;

$max_time = 0;
$min_time = 15000;
$avg_time = 0;
$total_time = 0;

print "Pinging ".$result[0]["server_name"]." with ".$result[0]["bytes"]." bytes of data:<br><br>\n";

for($i = 1; $i < sizeof($result); $i++){  
  if($result[$i]["time"] == -1){
    print "Request timed out<br>\n";
    $lost++;
    continue;
  }
  
  $total_time += $result[$i]["time"];
  $received++;
  if($result[$i]["time"] > $max_time) $max_time = $result[$i]["time"];
  else if($result[$i]["time"] < $min_time) $min_time = $result[$i]["time"];
  
  print "Reply from ".$result[0]["server_ip"].": bytes=".$result[0]["bytes"]." time=".$result[$i]["time"]."ms <br>\n";
  
}

$avg_time = round($total_time / $send);

print "<br>\n";
print "Ping statistics for ".$result[0]["server_ip"].":<br>\n";
print "Packets: Sent = ".$send.", Received = ".$received.", Lost = ".$lost." (".round((100 / $send) * $lost)."% loss)<br>\n";
print "Approximate roundtrip in milli-seconds:<br>\n";
print "Minimum = ".$min_time."ms, Maximum = ".$max_time."ms, Average = ".$avg_time."ms<br>\n";
?>
Reply With Quote
  #3 (permalink)  
Old 2004-01-19, 08:17 AM
JEK JEK is offline
Junior Member
 
Join Date: Apr 2003
Posts: 4
JEK
Default

Now you can see the error messages if there are any.
Are you sure the server is up on port 27015?

Code:
<?php
$fp = fsockopen('69.12.51.247',27015,$errno,$errstr,1);
if(!$fp){
echo 'Down'; // server is down
}else{
echo 'Up'; // server is up
exit;
}
?>
__________________
--
JEK
Reply With Quote
Must read Review for Serious PHP Developers


NuSphere PhpED 5.5 : The Staff of php-editors.com recently spent a few days working with NuSphere PhpED 5.5 (a popular PHP IDE) and NuCoder 2.0 (a PHP Encoding Utility), read up on all the details.

Sponsored Links
Reply

Thread Tools
Display Modes

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
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -5. The time now is 10:50 PM.


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO 3.1.0
© Copyright 2003-2008 www.php-editors.com. The ultimate PHP Editor and PHP IDE site.