Check Server Status with PHP


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

Hello Php Coders,

Here's a useful php code block for your projects to control server status.

Use this code blokc to report a server status result. I hope you'll like it.
Also; i suggest you to rest for a while on [2 KiÅŸilik Oyunlar](http://www.ikikisilikoyunlar.net) and [Oyunlar](http://www.cilekoyun.com) sites to fun. I think you'll like them. I wish you success on your profect and i hope everything'll be best for us.
Best codings!


Copy this code and paste it in your HTML
  1. <?
  2.  
  3. # Domain Name
  4. $domainName = "http://www.snipplr.com" ;
  5.  
  6. function DomainCheck($domainName){
  7. $startTime = microtime(true);
  8. $openDomain = fsockopen ($domainName, 80, $errno, $errstr, 10);
  9. $finishTime = microtime(true);
  10. $serverStatus = 0;
  11.  
  12. if (!$openDomain) $serverStatus = -1;
  13. else {
  14. fclose($openDomain);
  15. $status = ($finishTime - $startTime) * 1000;
  16. $serverStatus = floor($serverStatus);
  17. }
  18. return $serverStatus;
  19. }
  20.  
  21. $serverStatus = DomainCheck($domainName);
  22.  
  23. # Print
  24. if ($serverStatus != -1) {
  25. echo "Cannot reach the server!" ;
  26. } else {
  27. echo "Server's running well." ;
  28. }
  29.  
  30. ?>

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.