host = $host; $this->port = $port; $this->path = $path; $this->statusCode = $statusCode; $this->content = $content; } /** * @see ZendDiagnostics\CheckInterface::check() */ public function check() { $fp = @fsockopen($this->host, $this->port, $errno, $errstr, 10); if (!$fp) { return new Failure(sprintf('No http service running at host %s on port %s', $this->host, $this->port)); } $header = "GET {$this->path} HTTP/1.0\r\n"; $header .= "Host: {$this->host}\r\n"; $header .= "Connection: close\r\n\r\n"; fputs($fp, $header); $str = ''; while (!feof($fp)) { $str .= fgets($fp, 1024); } fclose($fp); if ($this->statusCode && !preg_match("/^HTTP\/[0-9]\.[0-9] {$this->statusCode}/", $str)) { return new Failure("Status code {$this->statusCode} does not match response from {$this->host}:{$this->port}{$this->path}"); } if ($this->content && strpos($str, $this->content) === false) { return new Failure("Content {$this->content} not found in response from {$this->host}:{$this->port}{$this->path}"); } return new Success(); } }