Testing to see if a website is online with php?

by 2 replies
3
#programming #online #php #website
  • You can use CURL, fsockopen() or even file_get_contents(). Or, you can run a command line ping using exec.

    For a real simple ping you can try this, it will simply return the amount of time to establish a connection to the host.

    Code:
    <?php
    
     = microtime(true);
     = fsockopen(, , , , );
     = microtime(true);
    
    if (!) {
    //site is down
     = FALSE;
    } else {
    //get response time
    fclose();
     = ( - ) * 1000;
     = floor();
  • Curl is best (the 'proper' way of doing HTTP requests via PHP0, but fsockopen is nice and easy to use

Next Topics on Trending Feed