Jump to content

Get server online status through php


mikeee324

Recommended Posts

Posted

I'm running a MTA server and a web server on a ubuntu vps.

I've been trying to ping the mta sa server using fsockopen and all I keep getting from it is connection refused.

How do I see if the server is running?

Posted

I used the example from the php site, but now it just seems to be saying my servers online when it isn't :S

I mean i can even use any port and it'll say it's online.

Anyone know how i can do this accurately?

$fp = fsockopen("udp://127.0.0.1", 22003, $errno, $errstr); 
if (!$fp)  
{ 
    echo "Offline"; 
} 
else  
{ 
    echo "Online"; 
    fclose($fp); 
     echo "</td>"; 
} 

I read somewhere too that the system might not know that theres nothing there until data is written/read to/from the port, i tried using fread but it didn't bring anything back at all.

Posted

Try to use TCP.

  
<?php 
    $fp = fsockopen("tcp://IP:PORT", PORT, $errno, $errstr); 
    if(isset($fp)){ 
        echo "Server is online !"; 
    } 
    else{ 
        echo "Server is offline !"; 
    } 
?> 
  

I don't test, but i think it will work :|

Posted

Both the web server and MTA server are on the same machine so that's why i'm using localhost.

Tried both tcp and udp on the main port and the web port of the mta server, it's not having any of it.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...