Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Prodentim Probiotics Specially Designed For The Health Of Your Teeth And Gums

Instant Grammar Checker - Correct all grammar errors and enhance your writing

Teach Your Child To Read

Powerful WordPress hosting for WordPress professionals

Disclosure: My content contains affiliate links.

31,037 questions

40,877 answers

573 users

How to check if the host (www.websitename.com) is online (alive) in PHP

Learn & Practice SQL


233 views
asked Nov 4, 2014 by avibootz
edited Nov 5, 2014 by avibootz

2 Answers

0 votes
function ping($host, $port = 80, $timeout = 5)
{
    $fsock = fsockopen($host, $port, $errno, $errstr, $timeout);
    if ( ! $fsock )
        return FALSE;
    else
        return TRUE;
}
      
$host = 'www.collectivesolver.com';
if( ping($host) )
   echo $host . " - is online<br>";
else
   echo $host . " - is down<br>";
   
/*
run:

www.collectivesolver.com - is online

*/




answered Nov 4, 2014 by avibootz
edited Nov 4, 2014 by avibootz
0 votes
function host_online($host)
{
    return (checkdnsrr($host, 'ANY'));
}
     
$host = 'www.collectivesolver.com';
if( host_online($host) ) 
   echo $host . " - is online
"; else echo $host . " - is down
"; /* run: www.collectivesolver.com - is online */




answered Nov 4, 2014 by avibootz
...