Skip to content

Instantly share code, notes, and snippets.

@cameronjacobson
Created November 13, 2012 00:01
Show Gist options
  • Save cameronjacobson/4062931 to your computer and use it in GitHub Desktop.
Save cameronjacobson/4062931 to your computer and use it in GitHub Desktop.
Simplistic TCP Monitor
<?php
error_reporting(0);
define('MONITOR_INTERVAL', 60);
$monitors = [
['127.0.0.1',25,80,110]
];
$loop = new React\EventLoop\LibEventLoop();
$loop->addPeriodicTimer(MONITOR_INTERVAL, function () use ($loop, $monitors) {
foreach($monitors as $monitor){
$host = array_shift($monitor);
foreach($monitor as $service){
$client = stream_socket_client('tcp://'.$host.':'.$service,$errno,$errstr,1);
if($client){
fclose($client);
}
else{
echo 'IS SERVICE RUNNING? - '.$host.' '.$service.PHP_EOL;
}
}
}
});
$loop->run();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment