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.

  1. <?php
  2.  
  3. function chkuri($link)
  4. {
  5. //$link is the website which i am checking
  6.  
  7. // If file_get_contents failed to retrieve
  8. // the page, it's not up
  9. if(!@file_get_contents($link)){
  10. return 'I\'m sorry, but the Ampache server is down. :(';
  11.  
  12. // It is up
  13. }else{
  14. return 'It\'s up! <a href="'.$link.'">Click here to go!</a>';
  15. }
  16. }
  17.  
  18. print '<h2>'.chkuri('http://martinez.homelinux.org/ampache').'</h2>';
  19.  
  20. ?>