Sitemap Generation

Overview

The sitemap generation system automatically creates XML sitemaps for all active radio stations, improving search engine visibility and making station pages more discoverable.

Key Features

Multiple Sitemap Files

  • Splits stations into chunks of 1000 URLs per file
  • Creates a sitemap index file (sitemap.xml)
  • Individual sitemaps stored in sitemaps/ directory
  • Automatic directory creation if needed

URL Structure

  • Homepage:
    • Priority: 1.0
    • Change frequency: daily
    • Added to first sitemap file
  • Station Pages:
    • Format: /listen/station-slug/id
    • Priority: 0.8
    • Change frequency: weekly
    • Clean URLs with station name slugs

Implementation Details

Database Integration

  • Queries only active stations (is_active = 1)
  • Uses PDO for secure database access
  • Error handling for database operations

XML Generation

  • Uses XMLWriter for efficient XML creation
  • Proper XML formatting and indentation
  • UTF-8 encoding support
  • Follows sitemap protocol standards

File Management

  • Creates sitemaps/ directory if missing
  • Numbered sitemap files (sitemap1.xml, sitemap2.xml, etc.)
  • Main sitemap index at root (sitemap.xml)
  • Proper file permissions handling

Usage

Running the Generator

  • Execute generate_sitemap.php script
  • No parameters required
  • Outputs generation statistics:
    • Total stations processed
    • Number of sitemap files created

Automated Updates with cPanel Cron Job

Follow these steps to set up automatic sitemap updates in cPanel:

  1. Log into your cPanel account
  2. Find and click on "Cron Jobs" (usually under Advanced section)
  3. In the "Add New Cron Job" section:
    • Select frequency: Choose "Once per day" for Common Settings
    • Or set custom schedule (e.g., @daily)
    • Command to add:
      php -q /path/to/your/site/generate_sitemap.php

      Replace /path/to/your/site with your actual website path

  4. Click "Add New Cron Job" to save

Important Notes:

  • Use absolute path to the script
  • Ensure PHP has execution permissions
  • Check logs for any errors after first run
  • Consider running during off-peak hours

Best Practices

  • Run periodically to keep sitemaps updated
  • Monitor script execution time
  • Check generated files for validity
  • Submit sitemap.xml to search engines
  • Monitor cron job execution in cPanel logs
  • Set up email notifications for cron job failures

Error Handling

Error Types

  • Database connection errors
  • File system permission issues
  • XML generation failures
  • Empty database scenarios

Error Response

  • Detailed error messages
  • Error logging to file
  • Clean error handling
  • Graceful script termination