try another color scheme:


Go Back   TECH6.0 > Get Techie > Programming > PHP/MySQL


PHP Script for monitoring services on your webserver

This is a discussion on PHP Script for monitoring services on your webserver within the PHP/MySQL section, part of the Programming category; I recently found this cool little script for checking which services are running on my webserver. For true effectiveness though, ...

Reply
 
LinkBack Thread Tools Display Modes
  #1  
Old 28-03-2009, 08:59 PM
TaL's Avatar
TaL TaL is offline

Moderator
 
Name: Steve
Join Date: Dec 2008
Location: Canada
Posts: 75
TaL will become famous soon enoughTaL will become famous soon enough
Default PHP Script for monitoring services on your webserver

I recently found this cool little script for checking which services are running on my webserver. For true effectiveness though, you should host this script on a second webserver so you can get feedback from the script even if your site is down.

PHP Code:
<?php
function check_port($port) {
    
$conn = @fsockopen("127.0.0.1"$port$errno$errstr0.2);
    if (
$conn) {
        
fclose($conn);
        return 
true;
    }
}

function 
server_report() {
    
$report = array();
    
$svcs = array('21'=>'FTP',
                  
'22'=>'SSH',
                  
'25'=>'SMTP',
                  
'80'=>'HTTP',
                  
'110'=>'POP3',
                  
'143'=>'IMAP',
                  
'3306'=>'MySQL',);
    foreach (
$svcs as $port=>$service) {
        
$report[$service] = check_port($port);
    }
    return 
$report;
}

$report server_report();
?>
<table>
    <tr>
        <td>Service</td>
        <td>Status</td>
    </tr>
    <tr>
        <td>MySQL</td>
        <td><?php echo $report['MySQL'] ? "Online" "Offline"?></td>
    </tr>
    <tr>
        <td>HTTP</td>
        <td><?php echo $report['HTTP'] ? "Online" "Offline"?></td>
    </tr>
    <tr>
        <td>SSH</td>
        <td><?php echo $report['SSH'] ? "Online" "Offline"?></td>
    </tr>
    <tr>
        <td>FTP</td>
        <td><?php echo $report['FTP'] ? "Online" "Offline"?></td>
    </tr>
    <tr>
        <td>SMTP</td>
        <td><?php echo $report['SMTP'] ? "Online" "Offline"?></td>
    </tr>
    <tr>
        <td>POP3</td>
        <td><?php echo $report['POP3'] ? "Online" "Offline"?></td>
    </tr>
    <tr>
        <td>IMAP</td>
        <td><?php echo $report['IMAP'] ? "Online" "Offline"?></td>
    </tr>
</table>
It is not very complex and gives you a nice quick overview of your server
__________________
Go placidly amid the noise and haste, and remember what peace there may be in silence

The Desiderada
Reply With Quote
  #2  
Old 28-03-2009, 09:07 PM
webwizzy's Avatar

Administrator
 
Name: Vinayak
Join Date: Feb 2008
Location: India
Phone: Samsung Wave
Posts: 1,116
webwizzy is just really nicewebwizzy is just really nicewebwizzy is just really nicewebwizzy is just really nicewebwizzy is just really nice
Send a message via Yahoo to webwizzy
Default

Works fine. Thanks for sharing
__________________
Always TAG and SHARE your threads
Submit your site to TECH6 Directory
TECH6 on Facebook - Like Us

Would you like to Link To Us | Support TECH6 by going Premium
Know more about me at Vinayaks.com | Follow TECH6 at Twitter


Reply With Quote
  #3  
Old 03-11-2011, 08:26 PM
No Avatar

Learner
 
Join Date: Oct 2011
Posts: 24
newsky is on a distinguished road
Default

Maybe this will help, I use it myself. Just open a sock to some port, see if it's open, and you know it's ok

Of course there are better alternatives which even check if a webpage works and such, but well, this does do the job for me.


function scanport($host, $port, $beschrijving){
$sock = @fsockopen($host, $port, $num, $error, 2);
if ($sock) {
$status = $beschrijving.'<font color="#009900"><strong>Up</strong></font><br>';
fclose($sock);
unset($sock);
} else {
#Fout! Nog een keer controleren!
unset($sock);
$sock = @fsockopen($host, $port, $num, $error, 2);
if ($sock) {
$status = $beschrijving.'<font color="#009900"><strong>Up</strong></font><br>';
fclose($sock);
unset($sock);
} else {
# Nu is het dus echt mis
$status = $beschrijving.'<font color="#FF0000"><strong>Down</strong></font><br>';
unset($sock);
}
}
echo $status;
}
__________________
quang cao nha dat
Reply With Quote
Reply

Bookmarks


Thread Tools
Display Modes




All times are GMT +5.5. The time now is 08:09 AM.

Contact Us - Tech6.com - Link to Us - Advertise - Submit Site - Privacy Statement - TOS - Top