Skip to content

Commit

Permalink
Curl option
Browse files Browse the repository at this point in the history
  • Loading branch information
SRWieZ committed Dec 24, 2024
1 parent ec0a809 commit ff3b528
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
24 changes: 24 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
7 changes: 7 additions & 0 deletions src/FlushDNS.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down

0 comments on commit ff3b528

Please sign in to comment.