From ff3b5282a9d0508a6451799f00b75c768d5adca5 Mon Sep 17 00:00:00 2001 From: Eser DENIZ Date: Tue, 24 Dec 2024 13:21:53 +0100 Subject: [PATCH] Curl option --- README.md | 24 ++++++++++++++++++++++++ src/FlushDNS.php | 7 +++++++ 2 files changed, 31 insertions(+) diff --git a/README.md b/README.md index 3332985..10a8e4a 100644 --- a/README.md +++ b/README.md @@ -35,6 +35,30 @@ $command = FlushDNS::getCommand(); $needsElevation = FlushDNS::needsElevation(); ``` +This library also comes some helpers fnuctions for Curl: + +```php +// Get options to ignore dns cache +$flushDnsOptions = FlushDNS::getCurlOpts(); + +// Make the request +$curl = curl_init(); +curl_setopt_array($curl, array_merge( + [ + CURLOPT_URL => "https://app.unolia.com/api/v1/domains", + CURLOPT_RETURNTRANSFER => true, + CURLOPT_HTTPHEADER => [ + "Accept: application/json", + "Authorization: Bearer 123" + ], + ], + $flushDnsOptions, +)); +$response = curl_exec($curl); +$domains = json_decode($response); +curl_close($curl); +``` + ## 📚 Use in command line You can also use this library in the command line by using the `flushdns` command. diff --git a/src/FlushDNS.php b/src/FlushDNS.php index bee0de7..f8d80c7 100644 --- a/src/FlushDNS.php +++ b/src/FlushDNS.php @@ -22,6 +22,13 @@ public static function getCommand(): string return 'sudo systemd-resolve --flush-caches'; } + public static function getCurlOpts(): array + { + return [ + CURLOPT_DNS_CACHE_TIMEOUT => 0, + ]; + } + /** * Check if the command needs elevation. */