How can PHP scripts be modified to prevent server timeouts when generating a sitemap?

When generating a large sitemap, PHP scripts may exceed the server's maximum execution time, resulting in a timeout error. To prevent this, you can use the `set_time_limit()` function to extend the script's execution time. Additionally, you can split the sitemap generation process into smaller chunks and use a loop to process each chunk within the set time limit.

// Extend the script's execution time to prevent server timeouts
set_time_limit(0);

// Split the sitemap generation process into smaller chunks
$pages = array("page1", "page2", "page3"); // Example array of pages
$chunkSize = 100; // Number of pages to process in each chunk

for ($i = 0; $i < count($pages); $i += $chunkSize) {
    $chunk = array_slice($pages, $i, $chunkSize);
    
    // Process the current chunk of pages
    foreach ($chunk as $page) {
        // Generate sitemap for $page
    }
}