• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 374
  • Last Modified:

Check status of TCP port with PHP

Below is some neglected code for checking TCP ports with PHP.
http://www.schwebdesigns.com/serverstatus/
http://www.schwebdesigns.com/serverstatus/status.zip

However I keep getting the following errors.
Can someone who has experience with fsocketopen function take a look at this?
I'm not sure why it cannot modify the header info, that's a new one to me.

Notice: Undefined variable: link in e:\inetpub\www\intranet\status\status.php on line 16
Notice: Undefined offset: 1 in e:\inetpub\www\intranet\status\status.php on line 16
Warning: Cannot modify header information - headers already sent by (output started at e:\inetpub\www\intranet\status\status.php:16) in e:\inetpub\www\intranet\status\status.php on line 23

PS if anyone knows of another PHP script that can monitor TCP ports and is reliable, please let me know.
This is the only script I came across after hours of looking.
0
calebudy
Asked:
calebudy
  • 2
1 Solution
 
ASCII_ManCommented:
Here's a completely modified version that will do what you want.

Just save is as status.php in the same directory as the original and update the server address specific setup lines as usual.
------------------
BEGIN status.php
------------------
<?php
//
// Modified Web Server Status v 1.2, Copyright 2002 By Ryan Schwiebert, visit http://www.schwebdesigns.com/
// See http://www.experts-exchange.com/Web/Web_Languages/PHP/Q_20554037.html
//

//
// BEGIN SETTINGS
//
//Please change to your server specifications
//

$live = "http://tech_01/status/live.gif";
$dead = "http://tech_01/status/dead.gif";
$defaultPort = 80;
$separator = ':';
$waitTime = 5;

// END SETTINGS

$link = $HTTP_GET_VARS['link'];

if($separator == ':'){
     if(strstr($link, $separator)){
          if(substr($link, 0, 6) == 'http://'){
               list($URI, $port) = explode($separator, substr($link, 6, 0));
          }
          else{
               list($URI, $port) = explode($separator, $link);
          }
     }
     else{
          $URI = str_replace('http://', '', $link);
          $port = $defaultPort;
     }
}
else{
     list($URI, $port) = explode($separator, $link);
}

if(empty($port)){
     $port = 80;
}

//Test the server connection
$checkURI = @fsockopen(server($URI), $port, $errno, $errstr, $waitTime);

if($checkURI){
     header("Location: $live");            
//     echo 'good';
}
else{
     header("Location: $dead");
//     echo 'dead';
}
function server($addr){
     if(strstr($addr,"/"))
          $addr = substr($addr, 0, strpos($addr, "/"));
     return $addr;
}
?>
------------------
END status.php
------------------

I'd also suggest that you award more points for a thread where you request someone to write a script for you.
0
 
ASCII_ManCommented:
Err, strike that comment.
I guess you didn't request the script, just some help... but hey, I thought it was ugly anyway :)
0
 
snoyes_jwCommented:
No comment has been added to this question in more than 21 days, so it is now classified as abandoned.

I will leave the following recommendation for this question in the Cleanup topic area:
    Accept: ASCII_Man {http:#8157543}

Any objections should be posted here in the next 4 days. After that time, the question will be closed.

snoyes_jw
EE Cleanup Volunteer
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now