'Speeding up the image generation process with PhantomJS and PHP

So I have this local script generate.php that loops through some special folder structure of websites on my localhost and executes a phantomJS script using the PHP exec function to generate Thumbnails (1200x800) for these projects (These are just websites/php/html).

The problem is, that its really slow. I have about 18 different images to be generated and it takes from 30sec up to a minute for only those 18 which is not what I want. Is there an option to run those 18 execs concurrently with php or maybe there is a phantomJS script that can handle many images at once. Hope someone has an idea.

foreach(folder level 1)
   foreach(folder level 2)
      exec(phantomjs render image)


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source