Need extra help with your Joomla site? Consider paid Joomla support by the developer of Chameleon and MetaMod.
- Index
- » MetaMod Pro
- » MetaMod Pro General Support
- » If my server is online
If my server is online
If my server is online
Is it somehow possible in Metamod pro to check if a server is Online (webserver port 80), and if it is online then show one module, and if it is offline then show an other module.
I will like to show on my hosted Joomla site, if my home server is online or offline.
Best regards
Mads
Re: If my server is online
Hi Mads,
yes, technically you can achieve this. There are some PHP code samples on the net for testing if a server is up or not. Most use the cURL library.
The only problem is that there's a timeout problem - most methods of checking will wait (or need to wait) for a few seconds to see if the connection succeeds. If you do this check in MetaMod, it means that the whole page gets held up for a few seconds which will make the page very slow.
Is this going to be acceptable for you?
Cheers,
Stephen
Re: If my server is online
Hi Stephen,
Thanks for your reply
I have search a little on google an came across this:
(fsockopen)
Code:
<?php
function server2($server, $port, $name) {
preg_match("/^(http:\/\/)?([^\/]+)/i", "$server", $match);
$host = $match[2];
preg_match_all("/\.([^\.\/]+)/",$host, $match);
$matches[0][0] = $matches[1][0];
$host = trim($host);
$socket = "";
@$socket = fsockopen("$host", $port, $errno, $errstr, 2);
if(!$socket) {
$socket = print("\n<br /><font color=\"red\">Server is Offline!</font>");
} else {
fclose($socket);
$socket = print("\n<br /><font color=\"green\">Server is Online</font>");
?>
<?php
}
}
$server = 'xxx.xxx.xxx.xxx';
if($server!=""){
server2($server,"21","ftp");
server2($server,"22","ssh"); //
server2($server,"23","telnet");
server2($server,"25","smtp");
server2($server,"80","http");
server2($server,"110","pop3");
server2($server,"443","https");
server2($server,"3306","MySQL");
server2($server,"8080","http_proxy");
}
else
{
$a=$_SERVER['xxx.xxx.xxx.xxx'];
}
?>
Will that also have timeout issues?
Or can I some how use that in MetaMod Pro?
Best regards
Mads
Re: If my server is online
The default timeout for fsockopen is 60 seconds, so you still have to give it a finite number e.g. 1
Try this:
$fp = @fsockopen("www.example.com", 80, $errno, $errstr, 1);// 1 is the timeout
if ($fp) return XXX;
else return YYY;
// replace XXX with module ID to display if site is up
// and YYY with the module to display if the site is down.
You might want to give it a 2 second timeout instead of 1 second, but you could base that on experiments about what happens when the site is actually up. If it's a quick connection, 1 second may be accurate most of the time.
Cheers,
Stephen
- Index
- » MetaMod Pro
- » MetaMod Pro General Support
- » If my server is online
Board Info
- Board Stats:
- Total Topics:
- 1689
- Total Polls:
- 6
- Total Posts:
- 5942
- Posts this week:
- 2
- User Info:
- Total Users:
- 7630
- Newest User:
- welch84998
- Members Online:
- 0
- Guests Online:
- 106
- Online:
- There are no members online
Forum Legend:
Topic
New
Locked
Sticky
Active
New/Active
New/Locked
New Sticky
Locked/Active
Active/Sticky
Sticky/Locked
Sticky/Active/Locked