PHP code example of elvesora / domain-lookup-php

1. Go to this page and download the library: Download elvesora/domain-lookup-php library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

elvesora / domain-lookup-php example snippets




lvesora\DomainLookup\Client;

$apiKey = getenv('ELVESORA_DOMAIN_LOOKUP_API_KEY');

if (!is_string($apiKey) || trim($apiKey) === '') {
    throw new RuntimeException('ELVESORA_DOMAIN_LOOKUP_API_KEY is not configured.');
}

$client = new Client($apiKey);

$result = $client->lookup(
    companyName: 'Acme Corporation',
    additionalContext: 'US software company',
);

if ($result->found) {
    echo $result->domain;       // acme.com
    echo $result->confidence;   // 1-100
} else {
    echo 'No reliable domain was found.';
}

$health = $client->ping();

echo $health->status; // ok

use Elvesora\DomainLookup\Exception\AuthenticationException;
use Elvesora\DomainLookup\Exception\DomainLookupException;
use Elvesora\DomainLookup\Exception\UsageLimitException;
use Elvesora\DomainLookup\Exception\ValidationException;

try {
    $client = new Client($apiKey);
    $result = $client->lookup('Acme Corporation');
} catch (\InvalidArgumentException $exception) {
    // Invalid local configuration, lookup input, timeout, base URL, or request ID.
} catch (AuthenticationException $exception) {
    // The API rejected an invalid or revoked API key.
} catch (ValidationException $exception) {
    // The API returned HTTP 422 validation errors.
    $errors = $exception->errors();
} catch (UsageLimitException $exception) {
    $limit = $exception->limit();
    $remaining = $exception->remaining();
} catch (DomainLookupException $exception) {
    if ($exception->retryable) {
        $retryAfter = $exception->retryAfter;
    }

    $requestId = $exception->requestId;
}

$client = new Client(
    apiKey: $apiKey,
    baseUrl: 'https://prospecting.elvesora.com/api',
    timeout: 100,
    connectTimeout: 10,
    userAgent: 'MyApplication/1.0',
);

$result = $client->lookup('Acme Corporation', requestId: 'request-01JABC123XYZ');