PHP code example of koh / indexnow

1. Go to this page and download the library: Download koh/indexnow library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

koh / indexnow example snippets


use Koh\IndexNow\IndexNowClient;
use Koh\IndexNow\Key;
use Koh\IndexNow\Submission;

$key = Key::derive($applicationSecret, 'www.example.org');
// Serve $key->value as text/plain at https://www.example.org/{$key->fileName()}

$client = new IndexNowClient($psr18Client, $psr17RequestFactory, $psr17StreamFactory);
$submission = Submission::forHost('www.example.org', $key, [
    'https://www.example.org/news/launch',
    'https://www.example.org/news/',
]);

foreach ($client->submitAll($submission) as $result) {
    if ($result->isRetryable()) {
        // queue again, after $result->retryAfterSeconds if the engine said so
    }
}