-
-
Save aisuhua/ebacd0c664b9d5f12b17dff066b6788b to your computer and use it in GitHub Desktop.
Simple PHP ping request
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?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); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment