I needed to develop this script in order to check whether or not my streaming media server was up. At first, I tried to use PHP’s system function with BASH’s wget, but that wasn’t working. I ended up using PHP’s file_get_contents.

<?php
function chkuri($link){
//$link is the website which i am checking
// If file_get_contents failed to retrieve
// the page, it's not up
  if(!file_get_contents($link)){
    return 'I\'m sorry, but the Ampache server is down. :(';
// It is up
  }else{
    return 'It\'s up! <a href="'.$link.'">Click here to go!</a>';
  }
}
print '<h2>'.chkuri('http://martinez.homelinux.org/ampache').'</h2>';
?>

Related posts: