EricMakesStuff\ServerMonitor\Monitors\HttpPingMonitor::runMonitor PHP Method

runMonitor() public method

public runMonitor ( )
    public function runMonitor()
    {
        if (empty($this->url)) {
            throw InvalidConfiguration::noUrlConfigured();
        }
        try {
            $guzzle = new Guzzle(['timeout' => $this->timeout, 'allow_redirects' => $this->allowRedirects]);
            $response = $guzzle->get($this->url);
            $this->responseCode = $response->getStatusCode();
            $this->responseContent = (string) $response->getBody();
        } catch (ClientException $e) {
            $response = $e->getResponse();
            $this->responseCode = $response->getStatusCode();
        } catch (ConnectException $e) {
        }
        if ($this->responseCode != '200' || !$this->checkResponseContains($this->responseContent, $this->checkPhrase)) {
            event(new HttpPingDown($this));
        } else {
            event(new HttpPingUp($this));
        }
    }

Usage Example

コード例 #1
0
 /** @test */
 public function it_throws_an_exception_for_nonexistent_url()
 {
     $httpPingMonitor = new HttpPingMonitor([]);
     $this->setExpectedException(InvalidConfiguration::class);
     $httpPingMonitor->runMonitor();
 }