Created
March 15, 2012 14:21
-
-
Save kevinlebrun/c2f1bd889e30d8e93b01 to your computer and use it in GitHub Desktop.
Service status checking with port scanning
This file contains 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
#!/usr/bin/php -q | |
<?php | |
function check_socket($host, $port) | |
{ | |
$conn = @fsockopen($host, $port, $errno, $errstr, 2); | |
if ($conn) { | |
fclose($conn); | |
return true; | |
} | |
return false; | |
} | |
echo 'localhost:8080 ' . (check_socket('localhost', 8080) ? 'OK' : 'NOK') . PHP_EOL; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment