Conditions | 2 |
Paths | 2 |
Total Lines | 31 |
Code Lines | 15 |
Lines | 0 |
Ratio | 0 % |
Tests | 13 |
CRAP Score | 2 |
Changes | 0 |
1 | <?php |
||
14 | 2 | protected function checkWhetherHostIsLive(string $host): bool |
|
15 | { |
||
16 | $statuses = array( |
||
17 | 2 | 200, |
|
18 | 301, |
||
19 | 302, |
||
20 | ); |
||
21 | |||
22 | // Initializing curl |
||
23 | 2 | $curlHandle = curl_init($host); |
|
24 | |||
25 | // Calling the host for a response |
||
26 | 2 | curl_setopt_array($curlHandle, array( |
|
|
|||
27 | 2 | CURLOPT_HEADER => true, |
|
28 | 2 | CURLOPT_NOBODY => true, |
|
29 | 2 | CURLOPT_RETURNTRANSFER => true, |
|
30 | 2 | CURLOPT_TIMEOUT => 10, |
|
31 | 2 | CURLOPT_USERAGENT => 'page-check/1.0', |
|
32 | )); |
||
33 | |||
34 | // Executing request |
||
35 | 2 | curl_exec($curlHandle); |
|
36 | |||
37 | // Collecting the status code and casting it to an integer |
||
38 | 2 | $status = (int) curl_getinfo($curlHandle, CURLINFO_HTTP_CODE); |
|
39 | |||
40 | // Closing curl |
||
41 | 2 | curl_close($curlHandle); |
|
42 | |||
43 | // Validating whether the http status is inside the allowed statuses array (Whether the page is live or not) |
||
44 | 2 | return in_array($status, $statuses) ? true : false; |
|
45 | } |
||
47 |