Replies: 8 comments 1 reply
-
Same here. Even after doing something like |
Beta Was this translation helpful? Give feedback.
-
@royduin @syclone In short: I created a laravel command and queue every xml request out.This way I can schedule it. These are the consequent actions I've taken to minimize memory use:
All this needs at it's peak moment is 60M of memory. My (shared) server can handle it now and I can schedule the task. Great! Job done 😎 (3 days later, hmmmm) |
Beta Was this translation helpful? Give feedback.
-
I ended up just writing it myself which is way faster and no memory issues: $sitemapIndex = SitemapIndex::create();
Product::select(['shop_id', 'slug', 'updated_at'])
->with('shop')
->whereNotNull('price')
->chunk(40000, function ($products, $chunk) use ($sitemapIndex) {
$sitemapName = 'products_sitemap_'.$chunk.'.xml';
$sitemap = '<?xml version="1.0" encoding="UTF-8"?>';
$sitemap .= '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml">';
foreach ($products as $product) {
$sitemap .= '<url>';
$sitemap .= '<loc>'.url($product->shop->slug.'/'.$product->slug).'</loc>';
$sitemap .= '<lastmod>'.$product->updated_at->format('Y-m-d').'</lastmod>';
$sitemap .= '</url>';
}
$sitemap .= '</urlset>';
file_put_contents(public_path($sitemapName), $sitemap);
$sitemapIndex->add($sitemapName);
});
$sitemapIndex->writeToFile(public_path('sitemap.xml')); |
Beta Was this translation helpful? Give feedback.
-
same issue here too but with much lower count of pages, < 500 or something.
|
Beta Was this translation helpful? Give feedback.
-
same here |
Beta Was this translation helpful? Give feedback.
-
I have returned to this sitemap package since Laravelium/laravel-sitemap does not support Laravel 9. Unfortunately, this issue still exists. I think I will just do @royduin's solution for now. |
Beta Was this translation helpful? Give feedback.
-
If running with ignition it might be that: |
Beta Was this translation helpful? Give feedback.
-
Hello there, i used lazycollections. $count = Product::query()
->where('publish', true)
->count();
$chunk = 40000;
$index = 1;
for ($i = 0; $i < $count;) {
$lazy = Product::query()
->where('publish', true)
->lazy()
->skip($i)
->take($chunk);
$i += $chunk;
Sitemap::create()
->add($lazy)
->writeToFile(public_path("products_$index.xml"));
$index++;
} Maybe it will help to someone. |
Beta Was this translation helpful? Give feedback.
-
I've got a command to generate a sitemap manually, something like: https://github.com/spatie/laravel-sitemap/issues/258#issuecomment-573346191 but with a lot of urls: 1.000.000 and the process is eating memory. I've put this in the foreach loop:
With the result:
So it's not cleaning up afterwards. Tried to debug it but I think it's a Laravel thing with views. When I just "return" in here: https://github.com/spatie/laravel-sitemap/blob/fced5910f1a80399115387557487e0bf261f37ab/src/Sitemap.php#L56:L65 instead of rendering the view it's not eating any memory anymore. Does Laravel keep the rendered view in the container or something?
Beta Was this translation helpful? Give feedback.
All reactions