Search by

PHP client for the tld-api TLD validation API (https://tld-api.ggio.fr), with local file caching

Package info

github.com/pierreminiggio/php-tld-api

pkg:composer/pierreminiggio/tld-api

Statistics

Installs: 7

Dependents: 0

Suggesters: 0

Stars: 1

Open Issues: 0

1.0.1 2026-09-13 22:20 UTC

This package is auto-updated.

Last update: 2026-09-13 22:21:59 UTC


README

PHP client for the tld-api API, which validates whether a TLD (Top-Level Domain) exists against the IANA TLD list.

Responses are cached locally in a JSON file for 2 months, to avoid hitting the remote API on every call.

Installation

composer require pierreminiggio/tld-api

Usage

use PierreMiniggio\TLDAPI\Validator;

$validator = new Validator();

$validator->validate('com'); // true
$validator->validate('notarealtld'); // false
$validator->validate('澳門'); // true, non-ASCII TLDs are supported

The first call for a given TLD hits the remote API and stores the result in the local cache (cache/tlds.json, ordered alphabetically by TLD). Any call made within the next 2 months for the same TLD is served from that cache. Once the cached entry is older than 2 months, the next call refreshes it from the API.

Cache folder permissions

The cache/ folder needs to be writable by the PHP process. If it isn't, validate() throws a RuntimeException telling you exactly which chmod -R 777 <folder> command to run.

Running the tests

composer install
vendor/bin/phpunit