Skip to content

Instantly share code, notes, and snippets.

@codearachnid
Created January 28, 2015 18:04
Show Gist options
  • Select an option

  • Save codearachnid/df5eed3a56447ec67713 to your computer and use it in GitHub Desktop.

Select an option

Save codearachnid/df5eed3a56447ec67713 to your computer and use it in GitHub Desktop.

Revisions

  1. Timothy Wood created this gist Jan 28, 2015.
    22 changes: 22 additions & 0 deletions ping.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,22 @@
    <?php

    function ping($host){
    if(exec('echo EXEC') == 'EXEC'){
    exec(sprintf('ping -c 1 -W 5 %s', escapeshellarg($host)), $res, $rval);
    } elseif( function_exists('fsocketopen') ){
    $port = 80;
    $timeout= 6;
    $fsock = fsockopen($host, $port, $errno, $errstr, $timeout);
    if ( ! $fsock ){
    $rval = 0;
    } else {
    $rval = 1;
    }
    }
    return $rval === 0;
    }


    /* check if the host is up $host can also be an ip address */
    $host = 'www.google.com';
    $up = ping($host);