Search code examples
phplaravelsitemaplaravel-sitemap

Sitemap Generator timed out, maximum execution time of 60 seconds exceeded


I need to generate a sitemap.

I am using spatie/laravel-sitemap. I have installed and published it but when I run the generator Symphony throws a fatal error: Maximum execution time of 60 seconds exceeded.

I have a huge list of links and left just one to test, but still getting the same error.

How to fix that? Here is my web.php code:

<?php

use Spatie\Sitemap\SitemapGenerator;

// this link throws a fatal error: Maximum execution time of 60 seconds exceeded
Route::get('sitemap', function(){

    SitemapGenerator::create('127.0.0.1:8000')->writeToFile('sitemap.xml');

    return 'sitemap created';

});

// this link is tested and fully working
Route::get('', function () {
    return view('home');
});

Solution

  • This is a common problem when working with long running scripts.

    Did you try using php function set_time_limit ?

    Try putting in the beginning of your script

    set_time_limit(300);