Welcome to the MetaMod and Chameleon Support Forums.

Before posting, please check out the FAQs.

helpme

 

Need extra help with your Joomla site? Consider paid Joomla support by the developer of Chameleon and MetaMod.

 

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. smile

Best regards
Mads

madseman
Beginner Modder
ranks
useravatar
Offline
5 Posts
Administrator has disabled public posting

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

Stephen Brandon
MetaMod / Chameleon developer
If you use MetaMod or Chameleon, please post a rating and a review at the Joomla! Extensions Directory: Chameleon | MetaMod

metamodguy
useravatar
Offline
3329 Posts
User info in posts
Administrator has disabled public posting

Re: If my server is online

Hi Stephen,

Thanks for your reply smile

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

madseman
Beginner Modder
ranks
useravatar
Offline
5 Posts
Administrator has disabled public posting

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

Stephen Brandon
MetaMod / Chameleon developer
If you use MetaMod or Chameleon, please post a rating and a review at the Joomla! Extensions Directory: Chameleon | MetaMod

metamodguy
useravatar
Offline
3329 Posts
User info in posts
Administrator has disabled public posting

Re: If my server is online

Thank you very much, it is working really great with 1 sec. smile

Thanks again

Cheers
Mads smile

madseman
Beginner Modder
ranks
useravatar
Offline
5 Posts
Administrator has disabled public posting

Board Info

Board Stats:
 
Total Topics:
1684
Total Polls:
6
Total Posts:
5940
Posts this week:
1
User Info:
 
Total Users:
5174
Newest User:
frashaomran
Members Online:
0
Guests Online:
105

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