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
a726fa024c
commit
638e6d9346
23
index.php
23
index.php
@ -11,15 +11,28 @@ if($_SERVER["REQUEST_URI"] == '/metrics') {
|
|||||||
$output = implode("\n", $output);
|
$output = implode("\n", $output);
|
||||||
} elseif(isset($c['httpurl'])) {
|
} elseif(isset($c['httpurl'])) {
|
||||||
$client = new GuzzleHttp\Client();
|
$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();
|
$output = $res->getBody()->getContents();
|
||||||
} elseif(isset($c['httpresponsetime'])) {
|
} elseif(isset($c['httpresponsetime'])) {
|
||||||
$client = new GuzzleHttp\Client();
|
$client = new GuzzleHttp\Client();
|
||||||
$output = NULL;
|
$output = NULL;
|
||||||
$res = $client->request('GET', $c['httpresponsetime'], [
|
|
||||||
'on_stats' => function (GuzzleHttp\TransferStats $stats) use (&$output) {
|
$options = [
|
||||||
$output = $stats->getTransferTime();
|
'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'])) {
|
if(isset($c['jsonelem'])) {
|
||||||
$c['value'] = getArrayValue($c['jsonelem'], json_decode($output, true));
|
$c['value'] = getArrayValue($c['jsonelem'], json_decode($output, true));
|
||||||
|
Loading…
Reference in New Issue
Block a user