0

I ZIP all my reports into a single ZIP file. When I turn off IDM, the download process tooks 20 seconds. But when enable IDM, it tooks 20 seconds to show the IDM download dialog, then after I click OK, it tooks another 20 seconds.

Can I do something bout this at my PHP code so that IDM user wont suffer? Or any explanation?

This is how I create Zip file in PHP:

$zip = new ZipArchive();
$filename = "Test.zip";
if($zip->open($filename, ZipArchive::CREATE)!==TRUE) die("cannot open <$filename>\n");

foreach([1,2,3,4,5] as $id) {
    $path = dirname($_SERVER['HTTP_REFERER']) . '/myreport.php';
    $ch = curl_init($path);
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query(['id' => $id]));
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_NOSIGNAL, 1);
    $get_file = curl_exec($ch);
    curl_close($ch);
    if($get_file === false) echo 'CURL ERROR: '.curl_error($ch);

    $zip->addFromString("Report $id.pdf", $get_file);
}

$zip->close();
header('Content-disposition: attachment; filename='.$filename);
header('Content-type: application/zip');
ob_clean();
readfile($filename);
unlink($filename);

die;
MrTux
  • 32,350
  • 30
  • 109
  • 146
Coisox
  • 1,002
  • 1
  • 10
  • 22
  • And an "IDM" is - what ...? (Tagging a question with tags that do not even have any description, isn't all that helpful.) – CBroe Mar 30 '22 at 10:28
  • @CBroe sorry bout that. I've edited my title – Coisox Mar 30 '22 at 10:33
  • These download managers often make multiple requests simultaneously, to downloads multiple parts of the response in parallel. That probably messes with your script here, in that either the already opened ZIP file might be blocked (so the next instance of the script would have to wait, until the previous one is done and releases it again), or it simply does "double the work", and therefor it takes more time overall. – CBroe Mar 30 '22 at 10:43
  • 1
    So you would have to find a way to _identify_ these "extra" requests, and cancel / reject them. – CBroe Mar 30 '22 at 10:44
  • Ok found the extra request. I've editted my question to include the final solution. BTW, how to mark ur comment as the correct answer? – Coisox Mar 31 '22 at 02:50

1 Answers1

0

See @CBroe's comment for the answer.

These download managers often make multiple requests simultaneously, to downloads multiple parts of the response in parallel. That probably messes with your script here, in that either the already opened ZIP file might be blocked (so the next instance of the script would have to wait, until the previous one is done and releases it again), or it simply does "double the work", and therefor it takes more time overall.
So you would have to find a way to identify these "extra" requests, and cancel / reject them.

Suraj Rao
  • 29,388
  • 11
  • 94
  • 103
Coisox
  • 1,002
  • 1
  • 10
  • 22