SA-MP Forums Archive
Server Monitor Problem - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Server (https://sampforum.blast.hk/forumdisplay.php?fid=6)
+--- Forum: Server Support (https://sampforum.blast.hk/forumdisplay.php?fid=19)
+--- Thread: Server Monitor Problem (/showthread.php?tid=572554)



Server Monitor Problem - Michael B - 29.04.2015

Hi!

So, I added a server monitor to my forum's index page.
I used the PHP code provided here.

However, after "installation", the monitor keeps displaying "Server is offline!", despite the fact everything is set up properly. I also tried to test more IP adresses of different servers, and I got the same result.

Any suggestions?


Re: Server Monitor Problem - Jimmy0wns - 29.04.2015

Show us the code, the API is working fine for me.


Re: Server Monitor Problem - Michael B - 29.04.2015

Is the same as the default, only the IP and port changed.
I'm using <iframe> HTML tag to display the PHP content on my index page, but this has no effect on the PHP query itself.
As you see at my forums, http://forum.ad-rp.ga, it is not working.

Could this be a webhost problem?


Re: Server Monitor Problem - Jimmy0wns - 29.04.2015

The PHP code I use is this:
PHP код:
// be sure to include the api before this, not the RCON API but the normal API. - I made the same mistake before by using the RCON API
$query = new SampQueryAPI('176.31.142.113''7777');
$aInformation $query->getInfo();
if(
$query->isOnline()) {
    
// server is online, show the iframe here
} else {
    
// server is offline, show an offline message here




Re: Server Monitor Problem - Abagail - 29.04.2015

I know for sure that my web host (I even had a technician confirm it) blocks off ports such as 7777, etc, and my host seems to be specifically picky about their security with that and wouldn't open these ports for me. As you saw in my IsUp service ( I no longer rent a VPS, so that's why it's down atm), I iframed the results(or you can even store it as a file and return the stuff directly to your webserver to the main website from my VPS hosting the service) directly because of this limitation.


Re: Server Monitor Problem - Michael B - 30.04.2015

Quote:
Originally Posted by Jimmy0wns
Посмотреть сообщение
The PHP code I use is this:
PHP код:
// be sure to include the api before this, not the RCON API but the normal API. - I made the same mistake before by using the RCON API
$query = new SampQueryAPI('176.31.142.113''7777');
$aInformation $query->getInfo();
if(
$query->isOnline()) {
    
// server is online, show the iframe here
} else {
    
// server is offline, show an offline message here

Is that for the class_query file?
What webhost are you using?

@Abagail: I know, I have a special premade plugin as server monitor, and I cannot use it just because of their " security" . Probably they are blocking the connection with their firewall.


Re: Server Monitor Problem - BroZeus - 30.04.2015

The problem is not with the code the problem is with your website host. As I have told earlier to you in some thread free hosts does not allow use of socket functions and those queries require use of socket functions.
There are two solution to this :
1) Either upgrade your website host to premium cuz most of premium host allows the use of socket function but not all premium host allows it so if you upgrade then be sure to inquire before upgrading.

2) Other solution is to fetch server data indirectly by api which is hosted on socket supported host, I uploaded a php file on my site which outputs the server info in JSON object form, here is how you can use it:
Quote:
http://brozeus.tk/api.php?srv=X.X.X.X&port=7777

Where X.X.X.X is the server ip and 7777 is the port.
Note that api is designed in such a way that if server is not online then it outputs "0".
Here is how you will use on your website.
PHP код:
<?php
//example
    
$url 'http://brozeus.tk/api.php?srv=X.X.X.X&port=7777';//replace ip and port here
    
$data file_get_contents($url);
    if(
$data == "0")//if server is offline
    
{
        echo 
"Server OFFLINE";
    }
    else
    {
        
$data json_decode($datatrue);//decoding data and converting to array
        
echo "Server ONLINE";
        echo 
"Host Name :".$data["hostname"];
        echo 
"Server gamemode : ".$data["gamemode"];
        echo 
"Map Name :".$data["mapname"]
        echo 
"Current Players : ".$data["players"];
        echo 
"Max Players : ".$data["maxplayers"];        
    }
?>
The keys name in array are case sensitive so make sure you use things as $data["players"], not $data["Players"]
All letters in array key will be in lowercase.


Re: Server Monitor Problem - Michael B - 30.04.2015

Thanks a lot BroZeus! I wasn't quite sure of this.