Refactor HTTP request handling for response status check
- Added try-catch block to handle GuzzleException - Updated logic to check for response status before processing
This commit is contained in:
parent
201c935330
commit
51ab7bcde6
12
index.php
12
index.php
@ -22,11 +22,19 @@ if($_SERVER["REQUEST_URI"] == '/metrics' || php_sapi_name() == 'cli') {
|
|||||||
$output = $stats->getTransferTime();
|
$output = $stats->getTransferTime();
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
$res = $client->request('GET', $c['http']['url'], $options);
|
$hasresponse = NULL;
|
||||||
|
try{
|
||||||
|
$res = $client->request('GET', $c['http']['url'], $options);
|
||||||
|
$hasresponse = true;
|
||||||
|
} catch(GuzzleHttp\Exception\GuzzleException $e) {
|
||||||
|
$hasresponse = false;
|
||||||
|
}
|
||||||
|
|
||||||
if (isset($c['http']['data']) && $c['http']['data'] == 'responsebody') {
|
if (isset($c['http']['data']) && $c['http']['data'] == 'responsebody') {
|
||||||
$output = $res->getBody()->getContents();
|
$output = $res->getBody()->getContents();
|
||||||
|
} elseif (isset($c['http']['data']) && $c['http']['data'] == 'hasresponse') {
|
||||||
|
$output = (int)$hasresponse;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user