Skip to content

thobandby/IndexNowListener

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

IndexNow Listener for Symfony

What this package does

This package provides a simple, event-driven integration for the IndexNow protocol in Symfony applications.

It allows you to notify search engines automatically when URLs change — by dispatching a Symfony event instead of handling API calls manually.


Why this exists

Search engines like Bing and Yandex support IndexNow, which allows pushing URL updates directly instead of waiting for crawlers.

In practice, this is often handled in an inconsistent way:

  • manual API calls spread across the codebase
  • delayed cronjobs
  • missing notifications for certain changes

This package centralizes that logic.

Instead of triggering IndexNow manually, you dispatch an event — the notification is handled in one place.


What this is (and what it is not)

This package is:

  • a small, focused utility for Symfony applications
  • event-driven and easy to integrate into existing workflows
  • designed to solve one specific problem: notifying IndexNow endpoints

This package is not:

  • a full SEO framework
  • a crawler or indexing system
  • a queue or background job system
  • a complete search engine integration layer

It is intentionally minimal and does not try to cover every possible use case, even though the notifier supports a small built-in retry mechanism for transient HTTP failures.


Use Cases

Useful for applications where content changes frequently:

  • Blogs / CMS systems
  • E-Commerce platforms (products, categories)
  • SEO-driven projects
  • Headless backends

Installation

composer require thorsten/index-now-listener

Configuration

Environment Variables (Symfony)

INDEXNOW_KEY=your_indexnow_key
INDEXNOW_KEY_LOCATION=https://yourdomain.com/your_indexnow_key.txt

INDEXNOW_KEY_LOCATION must be an absolute URL.

Symfony Service Configuration (recommended)

# config/services.yaml
Thorsten\IndexNowListener\Service\IndexNowNotifier:
  arguments:
    $key: '%env(INDEXNOW_KEY)%'
    $keyLocation: '%env(INDEXNOW_KEY_LOCATION)%'
    $searchEngine: !php/const Thorsten\IndexNowListener\Service\IndexNowNotifier::BING_ENDPOINT
    $maxRetries: 2
    $retryDelayMilliseconds: 250

Important:
The IndexNowNotifier does not read environment variables directly.
All configuration must be provided via dependency injection.


Usage

Using the Event (recommended)

use Thorsten\IndexNowListener\Event\IndexNowEvent;

$dispatcher->dispatch(new IndexNowEvent('https://yourdomain.com/page'));

Notify multiple URLs

$dispatcher->dispatch(new IndexNowEvent([
    'https://yourdomain.com/page1',
    'https://yourdomain.com/page2',
]));

Note: All URLs must belong to the same host.


Alternative: Direct usage (without events)

use Thorsten\IndexNowListener\Service\IndexNowNotifier;

$notifier->notify([
    'https://yourdomain.com/page1',
    'https://yourdomain.com/page2',
]);

Direct notifier usage applies the same safety checks as the event:

  • every URL must be a valid absolute URL
  • every URL must belong to the same host
  • keyLocation must be a valid absolute URL
  • non-2xx responses raise an exception
  • transient failures can be retried with the constructor options

For explicit HTTP failures, the notifier throws Thorsten\IndexNowListener\Exception\IndexNowNotificationException.

Known endpoints

  • IndexNowNotifier::BING_ENDPOINT
  • IndexNowNotifier::YANDEX_ENDPOINT
  • IndexNowNotifier::INDEXNOW_ENDPOINT

How it works

  • IndexNowEvent: Holds URLs
  • IndexNowListener: Reacts to events
  • IndexNowNotifier: Sends the HTTP request to the IndexNow API

The notifier is a pure service without hidden configuration logic.


Design Principles

  • No global state ($_ENV, $_SERVER)
  • No hidden configuration
  • Explicit dependencies
  • Fully testable

Requirements

  • PHP 8.2+
  • Symfony HttpClient
  • Symfony EventDispatcher (optional)

Supported package constraints:

  • php: ^8.2
  • symfony/event-dispatcher: ^6.4|^7.0|^8.0
  • symfony/http-client: ^6.4|^7.0|^8.0

Quality Checks

  • PHPUnit is configured via phpunit.xml.dist
  • GitHub Actions runs composer validate --strict and the test suite
  • SonarQube can import phpunit-report.xml and coverage.xml using sonar-project.properties

When to use (and when not)

Use it if:

  • You care about SEO freshness
  • Your content changes regularly
  • You want a clean, event-driven solution

Don’t use it if:

  • Your content rarely changes
  • You don’t need fast indexing

Author

Thorsten Baumann
https://baumann-it-dienstleistungen.de
info@baumann-it-dienstleistungen.de


This package is intentionally simple: no framework magic, no hidden behavior, just a clean way to integrate IndexNow into Symfony.

About

This bundle is designed to be non-intrusive. It leverages Symfony's EventSubscriberInterface to decouple the indexing logic from your business domain. You can easily trigger indexing by dispatching a custom IndexNowEvent or by hooking into existing Doctrine lifecycle events.

Topics

Resources

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages