baraja-core / index-now
Send ping to search engine by Index now protocol.
Installs: 35
Dependents: 0
Suggesters: 0
Security: 0
Stars: 3
Watchers: 1
Forks: 2
Open Issues: 0
pkg:composer/baraja-core/index-now
Requires
- php: ^8.0
Requires (Dev)
- phpstan/extension-installer: ^1.1
- phpstan/phpstan: ^1.0
- phpstan/phpstan-deprecation-rules: ^1.0
- phpstan/phpstan-nette: ^1.0
- phpstan/phpstan-strict-rules: ^1.0
- roave/security-advisories: dev-master
- spaze/phpstan-disallowed-calls: ^2.0
This package is auto-updated.
Last update: 2026-01-04 10:45:16 UTC
README
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.
π― Key Features
- 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
π How It Works
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
β β β
ποΈ Architecture
The library consists of a single IndexNow class with a straightforward design:
Components
| 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 |
Supported Search Engines
| Engine | Endpoint |
|---|---|
| Bing | https://www.bing.com/indexnow?key={key}&url={url} |
| Yandex | https://yandex.com/indexnow?key={key}&url={url} |
π¦ Installation
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-now
You can use the package manually by creating an instance of the internal classes.
Requirements
- PHP 8.0 or higher
- cURL extension enabled
π Basic Usage
Simple Example with Bing
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');
Using with Yandex
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');
Multiple Search Engines
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');
Custom Search Engine Endpoint
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');
π API Key Setup
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
π API Reference
Constructor
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 |
Methods
sendChangedUrl(string $url): void
Sends a notification to all configured search engine endpoints about a changed or new URL.
$indexNow->sendChangedUrl('https://example.com/updated-page');
addEndpointUrl(string $engine, string $endpointUrl): void
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}');
Constants
| 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 |
π‘ Best Practices
- 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
π External Resources
π€ Author
Jan Barasek - https://baraja.cz
π License
baraja-core/index-now is licensed under the MIT license. See the LICENSE file for more details.