ghwikipp: offline: Try to cook offline files on all available CPU cores.

From 410ba26735e4fd0bea1094e9f6b65597f8d7ebdc Mon Sep 17 00:00:00 2001
From: "Ryan C. Gordon" <[EMAIL REDACTED]>
Date: Wed, 7 May 2025 01:47:48 -0400
Subject: [PATCH] offline: Try to cook offline files on all available CPU
 cores.

This is Linux-only right now, but good enough for our purposes.
---
 make_offline_archive.php | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/make_offline_archive.php b/make_offline_archive.php
index 4deebff..9a988bf 100755
--- a/make_offline_archive.php
+++ b/make_offline_archive.php
@@ -14,9 +14,21 @@
 ];
 
 
-$max_children = 4;
+function get_max_children()
+{
+    $default_kids = 4;
+
+    // try to cook on all available CPU cores.
+    // !!! FIXME: this is Linux-specific. macOS, BSD, Windows want to do other things. Send a PR.  :)
+    $shell_output = shell_exec("nproc");
+    return is_numeric($shell_output) ? ((int) $shell_output) : $default_kids;
+}
+
+$max_children = get_max_children();
 $num_children = 0;
 
+//print("max_children = $max_children\n");
+
 function cook_tree_for_offline_html($srcdir, $dstdir, $input_dir)
 {
     global $supported_formats, $max_children, $num_children, $base_url, $raw_data;