?
Solved

Check status of TCP port with PHP

Posted on 2003-03-17
4
Medium Priority
?
364 Views
Last Modified: 2008-02-01
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
Comment
Question by:calebudy
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 2

Accepted Solution

by:
ASCII_Man earned 300 total points
ID: 8157543
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
 
LVL 2

Expert Comment

by:ASCII_Man
ID: 8157547
Err, strike that comment.
I guess you didn't request the script, just some help... but hey, I thought it was ugly anyway :)
0
 
LVL 33

Expert Comment

by:snoyes_jw
ID: 11934681
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question