php server status check


/ Published in: PHP
Save to your folder(s)



Copy this code and paste it in your HTML
  1. <?
  2.  
  3. # Domain Name
  4. $domainName = "http://www.symfony-projects.org" ;
  5.  
  6. # Function
  7. function DomainCheck($domainName){
  8. $startTime = microtime(true);
  9. $openDomain = fsockopen ($domainName, 80, $errno, $errstr, 10);
  10. $finishTime = microtime(true);
  11. $serverStatus = 0;
  12. # Control Structure
  13. if (!$openDomain) $serverStatus = -1;
  14. else {
  15. fclose($openDomain);
  16. $status = ($finishTime - $startTime) * 1000;
  17. $serverStatus = floor($serverStatus);
  18. }
  19. return $serverStatus;
  20. }
  21.  
  22. # Server Status
  23. $serverStatus = DomainCheck($domainName);
  24.  
  25. # Result
  26. if ($serverStatus != -1) {
  27. echo "Server is OFF right now" ;
  28. } else {
  29. echo "Server is ON; everyhing is OK." ;
  30. }
  31.  
  32. ?>

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.