webrium / indexnow
A lightweight, dependency-free PHP client for the IndexNow protocol.
Requires
- php: >=8.1
- ext-json: *
Requires (Dev)
- phpunit/phpunit: ^10.5
Suggests
- ext-curl: Required by the bundled CurlTransport. Not needed when you provide your own transport.
Provides
None
Conflicts
None
Replaces
None
This package is auto-updated.
Last update: 2026-12-02 10:19:54 UTC
README
A lightweight, dependency-free PHP client for the IndexNow protocol. Tell participating search engines (Bing, Yandex, Naver, Seznam, Yep and others) about new, updated or deleted pages the moment they change, instead of waiting for them to be crawled.
- Single and batch submissions (automatic splitting at 10,000 URLs per request)
- Key generation and verification-file helpers
- URL validation, de-duplication and percent-encoding of non-ASCII paths
- Typed results and status codes, with optional exceptions
- Swappable HTTP transport (cURL by default) and a network-free test double pattern
- PHP 8.1+, framework independent
Note: Google does not support IndexNow. Keep submitting your sitemap to Google Search Console.
Installation
composer require webrium/indexnow
Requirements: PHP 8.1 or higher and ext-json. The bundled transport uses ext-curl; it is not needed
if you provide your own transport.
Quick start
use Webrium\IndexNow\IndexNow; $indexNow = new IndexNow( host: 'example.com', key: 'your-indexnow-key', ); $result = $indexNow->submit('https://example.com/blog/my-new-post'); if ($result->isSuccessful()) { echo 'Submitted!'; }
Setting up the key
IndexNow proves that you own a site through a key file served from your own domain.
-
Generate a key (8 to 128 characters: letters, digits and dashes):
use Webrium\IndexNow\Key; $key = Key::generate(); // 32 hexadecimal characters by default
-
Publish the key file in your web root, so that
https://example.com/<key>.txtreturns the key:$key->writeFile('/var/www/example.com/public');
-
Store the key (for example in your
.env) and reuse it. Never generate a new key for every request. -
Optionally verify the setup once after deploying:
$indexNow = new IndexNow('example.com', $key); if (!$indexNow->verifyKeyFile()) { echo 'The key file is not reachable at ' . $indexNow->keyFileUrl(); }
If the key file lives somewhere else, pass its public URL:
$indexNow = new IndexNow( host: 'example.com', key: $key, keyLocation: 'https://example.com/files/' . $key->fileName(), );
Submitting many URLs
submitMany() accepts any iterable of URLs, removes duplicates and sends them in as few requests as
possible. The protocol allows up to 10,000 URLs per request, so larger lists are split automatically.
All URLs are validated before the first request is sent.
$urls = [ 'https://example.com/', 'https://example.com/about', 'https://example.com/blog/first-post', ]; foreach ($indexNow->submitMany($urls) as $result) { printf("%d URLs -> HTTP %d\n", count($result->urls), $result->statusCode); }
Use it to announce a whole site once, for example by feeding it the URLs of your sitemap.
Updated and deleted pages are submitted exactly like new ones.
URL rules
- URLs must be absolute
httporhttpsURLs. - URLs must belong to the configured host. Sub-domains are different hosts and need their own client and key.
- Spaces and non-ASCII characters (for example Persian, Arabic or Cyrillic slugs) are percent-encoded for you.
- A violation throws
InvalidUrlExceptionbefore anything is sent.
Results and errors
Submissions return a SubmissionResult. An HTTP error from the search engine does not throw; inspect
the result instead:
$result = $indexNow->submit('https://example.com/blog/my-new-post'); $result->isSuccessful(); // true for HTTP 200 and 202 $result->isRetryable(); // true for HTTP 429 and 5xx $result->statusCode; // 200, 202, 403, ... $result->status; // Webrium\IndexNow\ResponseStatus enum $result->message(); // human readable explanation $result->urls; // URLs contained in the request $result->body; // raw response body
| Code | Meaning |
|---|---|
| 200 | URLs submitted successfully |
| 202 | URLs received, the key is still being validated |
| 400 | Invalid request |
| 403 | Key not found, or it does not match the key file |
| 422 | URLs do not belong to the host, or the key does not match the schema |
| 429 | Too many requests (possible spam) |
Prefer exceptions? Chain throwIfFailed():
use Webrium\IndexNow\Exception\SubmissionException; try { $indexNow->submit($url)->throwIfFailed(); } catch (SubmissionException $e) { error_log($e->getMessage()); $e->result->isRetryable(); // decide whether to queue a retry }
Exceptions thrown by the library all implement Webrium\IndexNow\Exception\IndexNowException:
| Exception | Thrown when |
|---|---|
InvalidKeyException |
The key is invalid, or the key file cannot be written |
InvalidUrlException |
A URL or host is malformed, belongs to another host, or the list is empty |
TransportException |
No response could be obtained (network error, timeout) |
SubmissionException |
throwIfFailed() was called on a rejected submission |
Endpoints
Search engines share submissions with each other, so one request to the default endpoint is enough. You
can target a specific engine with the Endpoint enum, or pass any custom URL:
use Webrium\IndexNow\Endpoint; new IndexNow('example.com', $key, endpoint: Endpoint::Bing); new IndexNow('example.com', $key, endpoint: 'https://search.example/indexnow');
Available cases: IndexNow (default), Bing, Yandex, Naver, Seznam and Yep.
Custom transport
The client talks to the network through the small Transport interface. Implement it to reuse your own
HTTP client, set proxies or add logging:
use Webrium\IndexNow\Http\Request; use Webrium\IndexNow\Http\Response; use Webrium\IndexNow\Http\Transport; final class MyTransport implements Transport { public function send(Request $request): Response { // Send $request->method, $request->url, $request->headers and $request->body, // then return the status code, the body and the lower-cased response headers. return new Response(200); } } $indexNow = new IndexNow('example.com', $key, transport: new MyTransport());
The default CurlTransport accepts a timeout, a connect timeout and a user agent:
use Webrium\IndexNow\Http\CurlTransport; new IndexNow('example.com', $key, transport: new CurlTransport(timeout: 5, connectTimeout: 2));
Testing your integration
Inject a fake transport so that your tests never contact a real search engine:
final class FakeTransport implements Transport { /** @var list<Request> */ public array $requests = []; public function send(Request $request): Response { $this->requests[] = $request; return new Response(200); } }
A complete implementation lives in tests/Support/FakeTransport.php.
To run this library's own test suite (it makes no network requests to IndexNow):
composer install
composer test
License
Released under the MIT License.