public function run() : \Jyxo\Beholder\Result
{
// The \GuzzleHttp library is required
if (!class_exists(\GuzzleHttp\Client::class)) {
return new \Jyxo\Beholder\Result(\Jyxo\Beholder\Result::NOT_APPLICABLE, 'Guzzle library missing');
}
try {
$httpClient = new \GuzzleHttp\Client();
$httpRequest = new \GuzzleHttp\Psr7\Request('GET', $this->url, ['User-Agent' => 'JyxoBeholder']);
$httpResponse = $httpClient->send($httpRequest, [\GuzzleHttp\RequestOptions::CONNECT_TIMEOUT => 5, \GuzzleHttp\RequestOptions::TIMEOUT => 10]);
if (200 !== $httpResponse->getStatusCode()) {
throw new \Exception(sprintf('Http error: %s', $httpResponse->getReasonPhrase()));
}
if (isset($this->tests['body'])) {
$body = (string) $httpResponse->getBody();
if (strpos($body, $this->tests['body']) === false) {
$body = trim(strip_tags($body));
throw new \Exception(sprintf('Invalid body: %s', \Jyxo\StringUtil::cut($body, 128)));
}
}
return new \Jyxo\Beholder\Result(\Jyxo\Beholder\Result::SUCCESS, $this->url);
} catch (\Exception $e) {
return new \Jyxo\Beholder\Result(\Jyxo\Beholder\Result::FAILURE, $e->getMessage());
}
}