Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

iTechGuides is reader-supported. When you buy through links on our site, we may earn an affiliate commission. As an Amazon Associate I earn from qualifying purchases. Learn more

I built a PHP-generated XML sitemap to give Google a direct list of the pages I wanted it to discover. It helped address my indexation problem, but the sitemap was a discovery aid—not a command to index URLs. To claim it fixed the problem, the result needs to be supported by the site’s own Search Console records, server logs, or dated before-and-after evidence.

What a PHP sitemap can—and cannot—do

A sitemap lists URLs that a site owner considers canonical and wants search engines to discover. Google supports multiple sitemap formats; XML is a versatile choice for a sitemap generated by a PHP application. Google’s sitemap overview also notes that search engines can discover pages through crawlable links. A sitemap can supplement those links, especially on a large, new, or media-rich site; a small site with strong internal linking may not need one.

Submitting a sitemap is not an indexing request that Google must honor. Google says, “Keep in mind that submitting a sitemap is merely a hint: it doesn’t guarantee that Google will download the sitemap or use it for crawling URLs on the site.” Google Search Central’s sitemap instructions likewise explain that submission does not ensure that URLs will be crawled or indexed. A discovered or crawled page can still be excluded from search results.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

How to create a sitemap in PHP

Use the application’s published, canonical URLs as input. Do not blindly include every URL in a database: duplicate, noncanonical, private, or otherwise unwanted pages can make the sitemap less useful. XMLWriter is PHP’s forward-only interface for generating XML to a file or stream, with both object-oriented and procedural APIs; it is one practical way to write the document. See the PHP XMLWriter documentation.

Generate XML from canonical URLs

This example assumes $canonicalUrls has already been assembled from pages that are published and intended to appear in search. Replace the example host with your site’s actual canonical host. It writes a minimal sitemap containing absolute URLs; it does not discover or validate the pages for you.

<?php
$canonicalUrls = [
    'https://www.example.com/',
    'https://www.example.com/guides/php-sitemap',
];

$writer = new XMLWriter();
$writer->openMemory();
$writer->startDocument('1.0', 'UTF-8');
$writer->startElement('urlset');
$writer->writeAttribute('xmlns', 'http://www.sitemaps.org/schemas/sitemap/0.9');

foreach ($canonicalUrls as $url) {
    $writer->startElement('url');
    $writer->writeElement('loc', $url);
    $writer->endElement();
}

$writer->endElement();
$writer->endDocument();

$xml = $writer->outputMemory();
file_put_contents(__DIR__ . '/sitemap.xml', $xml);
?>

The XML writer escapes text values appropriately, but the application still needs to supply the right URLs. The loc values must be fully qualified absolute URLs, and the finished file must be well-formed XML. Keep the generated sitemap available at a stable, publicly reachable URL, such as https://www.example.com/sitemap.xml.

Respect sitemap limits

Google’s current sitemap documentation sets a per-file maximum of 50,000 URLs or 50 MB uncompressed. If the URL set exceeds either limit, split it into multiple sitemap files and, if useful, list those files in a sitemap index. These are file limits, not targets; a smaller sitemap is fine.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Serve the file without interference

After generation, request the sitemap over HTTP and confirm that it returns the XML you expect. Make sure PHP warnings, debug output, login requirements, or other access challenges are not being added to or blocking the response. Google must be able to fetch the file to process it. Google’s format and submission guidance covers valid sitemap structure and file requirements.

How to submit a sitemap to Google Search Console

  1. Make sure the sitemap is publicly reachable at its intended URL, then sign in to Google Search Console and select the property that matches the site.

  2. Open the Sitemaps report, enter the sitemap URL or path, and submit it. Google documents sitemap submission and report behavior in its submission instructions.

  3. Review the report for fetch or processing errors. A submitted sitemap’s status is not proof that every listed URL was crawled or indexed.

    Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

An alternative is to list the sitemap’s full URL in robots.txt, for example with a line such as Sitemap: https://www.example.com/sitemap.xml. This advertises the file’s location; it does not override crawling restrictions or guarantee inclusion in search.

Why pages may still not be indexed

A sitemap can help Google find URLs, but it cannot resolve every reason a page is absent from search. Diagnose the point where the process is failing instead of assuming that submission is the fix.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

How to tell whether the sitemap helped

To support the claim that a sitemap fixed an indexation problem, compare dated evidence from before and after it was deployed. Search Console can show whether Google processed the sitemap and provide URL-level inspection information; server logs can help establish whether Googlebot fetched the file or the listed pages. These signals help distinguish successful discovery from a later indexing decision.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

If pages began appearing after deployment, that timing alone does not establish that the sitemap caused the change. Internal linking, canonicalization, page quality, access controls, server capacity, and Google’s selection systems can also affect crawling and indexing. Describe the result as an observed outcome from the site’s records unless the evidence supports a stronger causal claim.

When the Indexing API is not the answer

Google does not recommend the Indexing API as a general replacement for sitemaps. Its documented use is for eligible short-lived job posting or livestream URLs; Google recommends retaining sitemaps for broader site coverage. See Google’s Indexing API guidance.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.