Skip to content

Instantly share code, notes, and snippets.

@mingomax
Last active April 18, 2017 14:14
Show Gist options
  • Save mingomax/597516affa6156f455f56f41d1f6b312 to your computer and use it in GitHub Desktop.
Save mingomax/597516affa6156f455f56f41d1f6b312 to your computer and use it in GitHub Desktop.
Class Monitoring Server
<?php
declare(strict_types = 1);
namespace Cellmidia\Monitoring;
/**
* Class Monitoring
* @package Cellmidia/Monitoring
*
* @author Domingos Teruel <mingomax@dteruel.net.br>
*/
class Monitoring
{
/**
* @var array
*/
private $conf;
/**
* Monitoring constructor.
* @param array $conf
*/
public function __construct(array $conf)
{
$this->conf = $conf;
}
/**
* @param string $host
* @param int $port
* @return boolean
*/
private function isServerUp(string $host, int $port): bool
{
$hostip = gethostbyname($host);
if ($hostip == $host) {
return false;
}
if (($x = @fsockopen($hostip, $port, $errno, $errstr, 5)) === false) {
return false;
}
fclose($x);
return true;
}
/**
* @return boolean
*/
private function isMysqlUp(): bool
{
if(($link = @mysqli_connect($this->conf['db.host'], $this->conf['db.user'], $this->conf['db.password'])) === false){
return false;
}
return true;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment