Testing to see if a website is online with php?

2 replies
Im looking to create a simple php script that "pings" a website to see if it is online and returns a response of either up, or down.

Anyone have any suggestions on how to go about this?
#online #php #website
  • Profile picture of the author unnatural
    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();
    {{ DiscussionBoard.errors[4484334].message }}
  • Profile picture of the author Content Publisher
    Curl is best (the 'proper' way of doing HTTP requests via PHP0, but fsockopen is nice and easy to use
    Signature
    Follow me as I build my content publishing business from $0 to a full time income.

    "The harder the conflict, the more glorious the triumph. What we obtain too cheaply, we esteem too lightly; it is dearness only that gives everything its value." - Thomas Paine
    {{ DiscussionBoard.errors[4487766].message }}

Trending Topics