@@ -15,7 +15,7 @@ discard block |
||
15 | 15 | public function init($destination,$httpStatus) |
16 | 16 | { |
17 | 17 | $this->destination = $destination; |
18 | - $this->httpStatus = $httpStatus; |
|
18 | + $this->httpStatus = $httpStatus; |
|
19 | 19 | } |
20 | 20 | |
21 | 21 | /** |
@@ -25,39 +25,39 @@ discard block |
||
25 | 25 | */ |
26 | 26 | public function run() |
27 | 27 | { |
28 | - $ch = curl_init(); |
|
28 | + $ch = curl_init(); |
|
29 | 29 | |
30 | - curl_setopt( $ch, CURLOPT_URL, $this->destination ); |
|
30 | + curl_setopt( $ch, CURLOPT_URL, $this->destination ); |
|
31 | 31 | |
32 | - curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true ); |
|
33 | - curl_setopt( $ch, CURLOPT_CUSTOMREQUEST, 'HEAD' ); |
|
34 | - curl_setopt( $ch, CURLOPT_HEADER, true ); |
|
35 | - curl_setopt( $ch, CURLOPT_NOBODY, true ); |
|
32 | + curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true ); |
|
33 | + curl_setopt( $ch, CURLOPT_CUSTOMREQUEST, 'HEAD' ); |
|
34 | + curl_setopt( $ch, CURLOPT_HEADER, true ); |
|
35 | + curl_setopt( $ch, CURLOPT_NOBODY, true ); |
|
36 | 36 | |
37 | - curl_setopt( $ch, CURLOPT_CONNECTTIMEOUT, 5 ); // connect timeout |
|
38 | - curl_setopt( $ch, CURLOPT_TIMEOUT, 10 ); // curl timeout |
|
37 | + curl_setopt( $ch, CURLOPT_CONNECTTIMEOUT, 5 ); // connect timeout |
|
38 | + curl_setopt( $ch, CURLOPT_TIMEOUT, 10 ); // curl timeout |
|
39 | 39 | |
40 | - // @todo configurable timeouts (do not put hundreds of parameters to the init method) |
|
41 | - // @todo Handle SSL support on self-signed cert errors |
|
42 | - // @todo Optional setup outgoing proxy host and port configuration |
|
40 | + // @todo configurable timeouts (do not put hundreds of parameters to the init method) |
|
41 | + // @todo Handle SSL support on self-signed cert errors |
|
42 | + // @todo Optional setup outgoing proxy host and port configuration |
|
43 | 43 | |
44 | - $httpError = null; |
|
45 | - $httpStatus = null; |
|
46 | - if ( curl_exec( $ch ) === false ) { |
|
47 | - $httpError = curl_error( $ch ); |
|
48 | - } else { |
|
49 | - $httpStatus = curl_getinfo( $ch, CURLINFO_HTTP_CODE ); |
|
50 | - } |
|
44 | + $httpError = null; |
|
45 | + $httpStatus = null; |
|
46 | + if ( curl_exec( $ch ) === false ) { |
|
47 | + $httpError = curl_error( $ch ); |
|
48 | + } else { |
|
49 | + $httpStatus = curl_getinfo( $ch, CURLINFO_HTTP_CODE ); |
|
50 | + } |
|
51 | 51 | |
52 | - curl_close( $ch ); |
|
52 | + curl_close( $ch ); |
|
53 | 53 | |
54 | - if ( !is_null( $httpError ) ) { |
|
55 | - return new Result(Result::STATUS_FAIL, 'Http resource request ' . $this->destination . ' has an error ['.$httpError.']'); |
|
56 | - } elseif ( $httpStatus == $this->httpStatus ) { |
|
57 | - return new Result(Result::STATUS_PASS, 'Http resource status for ' . $this->destination . ' is ok ['.$httpStatus.']'); |
|
58 | - } else { |
|
59 | - return new Result(Result::STATUS_WARN, 'Http resource status for ' . $this->destination . ' is different ['.$this->httpStatus.' was expected but '.$httpStatus.' was delivered]' ); |
|
60 | - } |
|
54 | + if ( !is_null( $httpError ) ) { |
|
55 | + return new Result(Result::STATUS_FAIL, 'Http resource request ' . $this->destination . ' has an error ['.$httpError.']'); |
|
56 | + } elseif ( $httpStatus == $this->httpStatus ) { |
|
57 | + return new Result(Result::STATUS_PASS, 'Http resource status for ' . $this->destination . ' is ok ['.$httpStatus.']'); |
|
58 | + } else { |
|
59 | + return new Result(Result::STATUS_WARN, 'Http resource status for ' . $this->destination . ' is different ['.$this->httpStatus.' was expected but '.$httpStatus.' was delivered]' ); |
|
60 | + } |
|
61 | 61 | } |
62 | 62 | |
63 | 63 | public function getIdentifier() |
@@ -12,7 +12,7 @@ discard block |
||
12 | 12 | private $destination = null; |
13 | 13 | private $httpStatus = null; |
14 | 14 | |
15 | - public function init($destination,$httpStatus) |
|
15 | + public function init($destination, $httpStatus) |
|
16 | 16 | { |
17 | 17 | $this->destination = $destination; |
18 | 18 | $this->httpStatus = $httpStatus; |
@@ -27,15 +27,15 @@ discard block |
||
27 | 27 | { |
28 | 28 | $ch = curl_init(); |
29 | 29 | |
30 | - curl_setopt( $ch, CURLOPT_URL, $this->destination ); |
|
30 | + curl_setopt($ch, CURLOPT_URL, $this->destination); |
|
31 | 31 | |
32 | - curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true ); |
|
33 | - curl_setopt( $ch, CURLOPT_CUSTOMREQUEST, 'HEAD' ); |
|
34 | - curl_setopt( $ch, CURLOPT_HEADER, true ); |
|
35 | - curl_setopt( $ch, CURLOPT_NOBODY, true ); |
|
32 | + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |
|
33 | + curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'HEAD'); |
|
34 | + curl_setopt($ch, CURLOPT_HEADER, true); |
|
35 | + curl_setopt($ch, CURLOPT_NOBODY, true); |
|
36 | 36 | |
37 | - curl_setopt( $ch, CURLOPT_CONNECTTIMEOUT, 5 ); // connect timeout |
|
38 | - curl_setopt( $ch, CURLOPT_TIMEOUT, 10 ); // curl timeout |
|
37 | + curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5); // connect timeout |
|
38 | + curl_setopt($ch, CURLOPT_TIMEOUT, 10); // curl timeout |
|
39 | 39 | |
40 | 40 | // @todo configurable timeouts (do not put hundreds of parameters to the init method) |
41 | 41 | // @todo Handle SSL support on self-signed cert errors |
@@ -43,20 +43,20 @@ discard block |
||
43 | 43 | |
44 | 44 | $httpError = null; |
45 | 45 | $httpStatus = null; |
46 | - if ( curl_exec( $ch ) === false ) { |
|
47 | - $httpError = curl_error( $ch ); |
|
46 | + if (curl_exec($ch) === false) { |
|
47 | + $httpError = curl_error($ch); |
|
48 | 48 | } else { |
49 | - $httpStatus = curl_getinfo( $ch, CURLINFO_HTTP_CODE ); |
|
49 | + $httpStatus = curl_getinfo($ch, CURLINFO_HTTP_CODE); |
|
50 | 50 | } |
51 | 51 | |
52 | - curl_close( $ch ); |
|
52 | + curl_close($ch); |
|
53 | 53 | |
54 | - if ( !is_null( $httpError ) ) { |
|
55 | - return new Result(Result::STATUS_FAIL, 'Http resource request ' . $this->destination . ' has an error ['.$httpError.']'); |
|
56 | - } elseif ( $httpStatus == $this->httpStatus ) { |
|
57 | - return new Result(Result::STATUS_PASS, 'Http resource status for ' . $this->destination . ' is ok ['.$httpStatus.']'); |
|
54 | + if (!is_null($httpError)) { |
|
55 | + return new Result(Result::STATUS_FAIL, 'Http resource request ' . $this->destination . ' has an error [' . $httpError . ']'); |
|
56 | + } elseif ($httpStatus == $this->httpStatus) { |
|
57 | + return new Result(Result::STATUS_PASS, 'Http resource status for ' . $this->destination . ' is ok [' . $httpStatus . ']'); |
|
58 | 58 | } else { |
59 | - return new Result(Result::STATUS_WARN, 'Http resource status for ' . $this->destination . ' is different ['.$this->httpStatus.' was expected but '.$httpStatus.' was delivered]' ); |
|
59 | + return new Result(Result::STATUS_WARN, 'Http resource status for ' . $this->destination . ' is different [' . $this->httpStatus . ' was expected but ' . $httpStatus . ' was delivered]'); |
|
60 | 60 | } |
61 | 61 | } |
62 | 62 |
@@ -6,7 +6,7 @@ |
||
6 | 6 | |
7 | 7 | // http resource status check |
8 | 8 | $httpStatusCheck = new \Leankoala\HealthFoundation\Check\Resource\Http\StatusCheck(); |
9 | -$httpStatusCheck->init('https://about.google/intl/com/',200); // PASS |
|
9 | +$httpStatusCheck->init('https://about.google/intl/com/', 200); // PASS |
|
10 | 10 | //$httpStatusCheck->init('https://about.google/intl/com/',404); // WARN |
11 | 11 | //$httpStatusCheck->init('https://www.there-is-no-domain-connected-'.time().'.com/index.html',200); // FAIL |
12 | 12 | $foundation->registerCheck($httpStatusCheck); |