Laravel – Too slow sitemap creation (Apache and Node.js installed on the same server)

I am running two Angular2+ project and a laravel api on my server together. The first angular project is a public website for users (SSR enabled), the second angular project is Admin Panel (SSR not enabled), these two projects runs on laravel api. I have a strange problem with sitemap creation.

I am using this library for sitemap creation and also laravel api is running on Apache Server.

The problem is
Sitemap creation process is taking too much time (apr. 70 seconds)
This problem occurred after enabling server side rendering on my angular project. If I disable SSR, the problem not occurs.
While angular ssr project is running based on Node.js, sitemap creation process increases Node.js resource usage (CPU up to 85%) and therefore this process takes 1 minute to complete. This is strange because laravel is running on apache server and admin can create sitemap, because of ssr is not enabled for admin panel, it shouldn’t be related with Node.js server.

Here is my ssr enabled angular project (when idle):
ssr enabled angular

Here is my process list:
enter image description here

This ss taken when executing following code:
$sitemap = SitemapGenerator::create($website->url)->getSitemap();

As you can see Node process is consuming all cpu resource.

How did I understand sitemap generation is getting slow the performance?

Sitemap generation code here:

        if($posts == null || count($posts) == 0) {
            return 'Bu siteye ait link verisi bulunamad─▒.!';
            $sitemap = SitemapGenerator::create($website->url)->getSitemap(); //<-- This line
            //code never reach here for testing purpose
            foreach ($posts as $post) {
                //do something

If I comment the $sitemap = SitemapGenerator::create($website->url)->getSitemap(); line the request is finished in 2 seconds otherwise it is finished in 70 seconds. While this code is executing, Node.js cpu usage is hitting up.

And also if I stop the ssr with terminal sudo pm2 stop, I can generate my sitemap in 2 seconds.

So what kind of relation exists between this request and Node.js process?

Is this an Apache bug?

Is this a Node.js bug? or something related with this library?

How can I fix it?

My Apache configuration file for ssr enabled website:

<VirtualHost *:80>

        ServerAdmin [email protected]
        DocumentRoot /var/www/html/

        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined


        <Directory /var/www/html/>
                Options -Indexes +FollowSymLinks

                RewriteEngine on

                # Don't rewrite files or directories
                RewriteCond %{REQUEST_FILENAME} -f [OR]
                RewriteCond %{REQUEST_FILENAME} -d
                RewriteRule ^ - [L]

                # Rewrite everything else to index.html to allow HTML5 state links
                RewriteRule ^ index.html [L]

    ProxyPreserveHost On

    ProxyPass / http://localhost:4000/
    ProxyPassReverse / http://localhost:4000/

  ErrorDocument 403

My Apache configuration file for laravel api:

<VirtualHost *:80>

        ServerAdmin [email protected]
        DocumentRoot /var/www/html/
        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined


        <Directory /var/www/html/>
                AllowOverride All



My environment;

  • Node v10.22.0
  • Apache v2.4.29
  • PHP v7.4.14
  • Laravel v6.0
  • Laravel Sitemap v5.5


  • Ubuntu Server – 18.04.4
  • 8 GB RAM

Thank you

Source: Ask PHP