Skip to content

Instantly share code, notes, and snippets.

@kevinlebrun
Created March 15, 2012 14:21
Show Gist options
  • Save kevinlebrun/c2f1bd889e30d8e93b01 to your computer and use it in GitHub Desktop.
Save kevinlebrun/c2f1bd889e30d8e93b01 to your computer and use it in GitHub Desktop.
Service status checking with port scanning
#!/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