Refactor Guzzle HTTP requests for flexibility and proxy support
Restructured Guzzle HTTP requests to allow for additional options like proxy support, enhancing flexibility in handling different types of requests.
This commit is contained in:
parent
bcb0d0b23d
commit
1dfddd64ba
23
index.php
23
index.php
@ -11,15 +11,28 @@ if($_SERVER["REQUEST_URI"] == '/metrics') {
|
||||
$output = implode("\n", $output);
|
||||
} elseif(isset($c['httpurl'])) {
|
||||
$client = new GuzzleHttp\Client();
|
||||
$res = $client->get($c['httpurl']);
|
||||
|
||||
$options = [];
|
||||
if (isset($c['proxy'])) {
|
||||
$options['proxy'] = $c['proxy'];
|
||||
}
|
||||
|
||||
$res = $client->request('GET', $c['httpurl'], $options);
|
||||
$output = $res->getBody()->getContents();
|
||||
} elseif(isset($c['httpresponsetime'])) {
|
||||
$client = new GuzzleHttp\Client();
|
||||
$output = NULL;
|
||||
$res = $client->request('GET', $c['httpresponsetime'], [
|
||||
'on_stats' => function (GuzzleHttp\TransferStats $stats) use (&$output) {
|
||||
$output = $stats->getTransferTime();
|
||||
}]);
|
||||
|
||||
$options = [
|
||||
'on_stats' => function (GuzzleHttp\TransferStats $stats) use (&$output) {
|
||||
$output = $stats->getTransferTime();
|
||||
}
|
||||
];
|
||||
if (isset($c['proxy'])) {
|
||||
$options['proxy'] = $c['proxy'];
|
||||
}
|
||||
|
||||
$res = $client->request('GET', $c['httpresponsetime'], $options);
|
||||
}
|
||||
if(isset($c['jsonelem'])) {
|
||||
$c['value'] = getArrayValue($c['jsonelem'], json_decode($output, true));
|
||||
|
Loading…
Reference in New Issue
Block a user