function ag_enam_fetch_parallel($date, $commodities) {

    $multi = curl_multi_init();
    $channels = [];
    $max_parallel = 5; // ⚠️ IMPORTANT (do NOT increase too much)

    $chunks = array_chunk($commodities, $max_parallel, true);
    $results = [];

    foreach ($chunks as $chunk) {

        $channels = [];

        foreach ($chunk as $id => $name) {

            $payload = json_encode([
                "date" => $date,
                "liveDate" => $date,
                "commodityIds" => [$id]
            ]);

            $ch = curl_init("https://api.agmarknet.gov.in/v1/prices-and-arrivals/commodity-market/daily-report-weighted");

            curl_setopt_array($ch, [
                CURLOPT_RETURNTRANSFER => true,
                CURLOPT_POST => true,
                CURLOPT_POSTFIELDS => $payload,
                CURLOPT_HTTPHEADER => [
                    "Content-Type: application/json",
                    "User-Agent: Mozilla/5.0"
                ],
                CURLOPT_TIMEOUT => 20,          // ✅ HARD timeout
                CURLOPT_CONNECTTIMEOUT => 10,  // ✅ connection timeout
            ]);

            curl_multi_add_handle($multi, $ch);
            $channels[$id] = $ch;
        }

        do {
            $status = curl_multi_exec($multi, $running);
            curl_multi_select($multi); // ✅ VERY IMPORTANT (prevents CPU hang)
        } while ($running && $status == CURLM_OK);

        foreach ($channels as $id => $ch) {
            $content = curl_multi_getcontent($ch);

            if ($content) {
                $results[$id] = json_decode($content, true);
            } else {
                $results[$id] = null; // failed safely
            }

            curl_multi_remove_handle($multi, $ch);
        }

        // ⚡ small delay → avoid API block
        usleep(300000); // 0.3 sec
    }

    curl_multi_close($multi);

    return $results;
}
<?xml version="1.0" encoding="UTF-8"?>
<!-- This sitemap was dynamically generated on April 20, 2026 at 6:32 am by All in One SEO v4.6.5 - the original SEO plugin for WordPress. -->

<?xml-stylesheet type="text/xsl" href="https://mandibhav.com/default-sitemap.xsl?sitemap=root"?>
<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
	<sitemap>
		<loc><![CDATA[https://mandibhav.com/post-sitemap.xml]]></loc>
		<lastmod><![CDATA[2026-04-18T04:40:00+00:00]]></lastmod>
	</sitemap>
	<sitemap>
		<loc><![CDATA[https://mandibhav.com/post-sitemap2.xml]]></loc>
		<lastmod><![CDATA[2021-04-08T09:46:10+00:00]]></lastmod>
	</sitemap>
	<sitemap>
		<loc><![CDATA[https://mandibhav.com/post-sitemap3.xml]]></loc>
		<lastmod><![CDATA[2020-05-30T03:44:25+00:00]]></lastmod>
	</sitemap>
	<sitemap>
		<loc><![CDATA[https://mandibhav.com/page-sitemap.xml]]></loc>
		<lastmod><![CDATA[2026-03-31T07:37:18+00:00]]></lastmod>
	</sitemap>
	<sitemap>
		<loc><![CDATA[https://mandibhav.com/attachment-sitemap.xml]]></loc>
		<lastmod><![CDATA[2025-09-25T04:35:27+00:00]]></lastmod>
	</sitemap>
	<sitemap>
		<loc><![CDATA[https://mandibhav.com/category-sitemap.xml]]></loc>
		<lastmod><![CDATA[2026-04-18T04:40:00+00:00]]></lastmod>
	</sitemap>
</sitemapindex>
