Last active
April 18, 2017 14:14
-
-
Save mingomax/597516affa6156f455f56f41d1f6b312 to your computer and use it in GitHub Desktop.
Class Monitoring Server
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
<?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