Installation Add the bundle via Composer:
composer require cwd/whois-bundle
Enable the bundle in config/bundles.php (Symfony) or AppKernel.php (Laravel via Symfony bridge):
// config/bundles.php
return [
// ...
Cwd\WhoisBundle\CwdWhoisBundle::class => ['all' => true],
];
Basic Usage
Inject the WhoisService into a controller or service:
use Cwd\WhoisBundle\Service\WhoisService;
class DomainController extends Controller
{
public function __construct(private WhoisService $whois)
{
}
public function showWhois(string $domain)
{
$result = $this->whois->lookup($domain);
return response()->json($result);
}
}
First Query
Call the lookup() method with a domain name:
$whoisData = $this->whois->lookup('example.com');
Output will be a parsed array of WHOIS record data (e.g., registrant, expiry, nameservers).
Domain Validation Use WHOIS to validate domain ownership or registration status:
$domain = 'example.com';
$whois = $this->whois->lookup($domain);
if (isset($whois['registrar']) && $whois['status'] === 'active') {
// Domain is valid and active
}
Expiry Date Checks Extract expiry dates for renewal reminders:
$expiryDate = $whois['expiration_date'] ?? null;
$daysUntilExpiry = Carbon::parse($expiryDate)->diffInDays();
Nameserver Lookup Fetch authoritative nameservers for DNS configuration:
$nameservers = $whois['nameserver'] ?? [];
Batch Processing Process multiple domains efficiently (e.g., for bulk checks):
$domains = ['example.com', 'test.org'];
$results = collect($domains)->map(fn($d) => $this->whois->lookup($d));
$whoisData = Cache::remember("whois_{$domain}", now()->addHours(24), fn() => $this->whois->lookup($domain));
use Illuminate\Cache\RateLimiting\Limit;
RateLimiter::for('whois', function () {
return Limit::perMinute(10); // 10 requests/minute
});
try {
$whois = $this->whois->lookup($domain);
} catch (\Exception $e) {
return response()->json(['error' => 'WHOIS lookup failed'], 500);
}
Rate Limits
Inconsistent Data Formats
.com vs .io). The bundle may not parse all fields uniformly.$registrant = $whois['registrant'] ?? $whois['registrar'] ?? null;
Private Registration
status: private or registrant: Redacted and handle accordingly.Deprecated TLDs
.info) have deprecated WHOIS services. Queries may fail silently.Network Timeouts
$whois = new RetryableWhoisService($this->whois, 3); // Retry 3 times
# config/packages/cwd_whois.yaml
verbose: true
$rawData = $this->whois->rawLookup($domain); // If method exists
Custom Parsers Extend the bundle’s parser for unsupported TLDs:
use Cwd\WhoisBundle\Parser\WhoisParserInterface;
class CustomWhoisParser implements WhoisParserInterface
{
public function parse(string $rawData): array
{
// Custom logic for TLD-specific parsing
}
}
Register it in the bundle’s services.
Proxy Support Route WHOIS queries through a proxy for anonymity or compliance:
# config/packages/cwd_whois.yaml
proxy: http://your-proxy:port
Event Listeners Trigger actions on WHOIS events (e.g., expiry alerts):
// In a service provider
$this->app->make('events')->listen(
\Cwd\WhoisBundle\Event\WhoisLookupEvent::class,
function ($event) {
// Handle event (e.g., log, notify)
}
);
Fallback Providers Implement a fallback to alternative WHOIS services (e.g., ARIN, RIPE) if the primary fails:
$this->whois->setFallbackProvider(new ArinWhoisProvider());
How can I help you explore Laravel packages today?