Easy-to-use PHP library implementing the IndexNow protocol that allows websites to notify search engines whenever content on any URL is updated or created, enabling instant crawling and discovery.
- Instant indexing - Notify search engines immediately when your content changes
- Multi-engine support - Built-in support for Bing and Yandex, with ability to add custom endpoints
- Simple API - Single method call to ping search engines about URL changes
- Lightweight - Zero external dependencies, uses native PHP cURL
- PHP 8.0+ - Modern PHP with strict typing and clean architecture
The IndexNow protocol is a simple ping mechanism that informs search engines about recent changes to your website content:
- Generate API Key - Create a unique API key and host it as a text file at your domain root
- Initialize Service - Create an
IndexNowinstance with your API key and target search engine - Send Notifications - Call
sendChangedUrl()whenever you update or create content - Search Engine Crawls - The search engine receives the ping and prioritizes crawling your URL
┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐
│ Your Website │ │ IndexNow │ │ Search Engine │
│ │ │ Library │ │ (Bing/Yandex) │
└────────┬────────┘ └────────┬────────┘ └────────┬────────┘
│ │ │
│ Content Updated │ │
│──────────────────────>│ │
│ │ │
│ │ HTTP GET with URL │
│ │──────────────────────>│
│ │ │
│ │ 200 OK │
│ │<──────────────────────│
│ │ │
│ │ │ Crawler visits
│<─────────────────────────────────────────────│ your URL
│ │ │
The library consists of a single IndexNow class with a straightforward design:
| Component | Description |
|---|---|
IndexNow |
Main service class handling API key management and endpoint communication |
ENGINE_BING |
Constant for Bing search engine identifier |
ENGINE_YAHOO |
Constant for Yandex search engine identifier |
ENGINE_ENDPOINT |
Predefined endpoint URL templates for supported engines |
| Engine | Endpoint |
|---|---|
| Bing | https://www.bing.com/indexnow?key={key}&url={url} |
| Yandex | https://yandex.com/indexnow?key={key}&url={url} |
It's best to use Composer for installation, and you can also find the package on Packagist and GitHub.
To install, simply use the command:
$ composer require baraja-core/index-nowYou can use the package manually by creating an instance of the internal classes.
- PHP 8.0 or higher
- cURL extension enabled
use Baraja\IndexNow\IndexNow;
// Create service instance for Bing
$indexNow = new IndexNow(
apiKey: 'your-api-key-here',
searchEngine: IndexNow::ENGINE_BING
);
// Notify search engine about changed URL
$indexNow->sendChangedUrl('https://example.com/updated-page');use Baraja\IndexNow\IndexNow;
// Create service instance for Yandex
$indexNow = new IndexNow(
apiKey: 'your-api-key-here',
searchEngine: IndexNow::ENGINE_YAHOO
);
// Send notification
$indexNow->sendChangedUrl('https://example.com/new-article');You can notify multiple search engines by adding additional endpoints:
use Baraja\IndexNow\IndexNow;
// Start with Bing
$indexNow = new IndexNow(
apiKey: 'your-api-key-here',
searchEngine: IndexNow::ENGINE_BING
);
// Add Yandex endpoint
$indexNow->addEndpointUrl(
engine: IndexNow::ENGINE_YAHOO,
endpointUrl: IndexNow::ENGINE_ENDPOINT[IndexNow::ENGINE_YAHOO]
);
// This will now notify both Bing and Yandex
$indexNow->sendChangedUrl('https://example.com/updated-content');You can add custom endpoints for other search engines that support the IndexNow protocol:
use Baraja\IndexNow\IndexNow;
$indexNow = new IndexNow(
apiKey: 'your-api-key-here',
searchEngine: IndexNow::ENGINE_BING
);
// Add a custom endpoint (use {key} and {url} placeholders)
$indexNow->addEndpointUrl(
engine: 'custom-engine',
endpointUrl: 'https://custom-search.com/indexnow?key={key}&url={url}'
);
$indexNow->sendChangedUrl('https://example.com/page');Before using IndexNow, you need to set up your API key:
- Generate a key - Create a unique alphanumeric string (e.g.,
ecc3bf28ed494de4b01e754cf6dff0d5) - Create a key file - Place a text file named
{your-key}.txtat your website root containing the key itself - Verify accessibility - Ensure
https://yourdomain.com/{your-key}.txtreturns your key
Example key file location:
https://example.com/ecc3bf28ed494de4b01e754cf6dff0d5.txt
The content of this file should be:
ecc3bf28ed494de4b01e754cf6dff0d5
public function __construct(
string $apikey,
string $searchEngine = self::ENGINE_BING
)| Parameter | Type | Default | Description |
|---|---|---|---|
$apikey |
string | - | Your IndexNow API key |
$searchEngine |
string | ENGINE_BING |
Initial search engine to use |
Sends a notification to all configured search engine endpoints about a changed or new URL.
$indexNow->sendChangedUrl('https://example.com/updated-page');Adds a new search engine endpoint. The {key} placeholder in the URL will be automatically replaced with your API key.
$indexNow->addEndpointUrl('custom', 'https://search.com/indexnow?key={key}&url={url}');| Constant | Value | Description |
|---|---|---|
ENGINE_BING |
'bing' |
Bing search engine identifier |
ENGINE_YAHOO |
'yahoo' |
Yandex search engine identifier |
ENGINE_ENDPOINT |
array | Mapping of engine names to endpoint URLs |
- Call on actual changes - Only ping when content genuinely changes to maintain trust with search engines
- Batch wisely - For bulk updates, consider spacing out notifications
- Verify key setup - Ensure your API key file is publicly accessible before making calls
- Monitor responses - While the library doesn't return responses, monitor your search console for indexing status
- Use in production - IndexNow is designed for production environments; avoid excessive testing calls
Jan Barasek - https://baraja.cz
baraja-core/index-now is licensed under the MIT license. See the LICENSE file for more details.