How to ensure download does not breaks using PHP Curl
<p>I have using PHP's Curl function to download a list of pdfs from the backend. But sometimes some pdfs are corrupted. </p>

<p>I think, this happens because the downloads breaks and it will start to download the next pdf before completing the previous download. </p>

<p>Any idea how to prevent this? I am using the code below:</p>

<pre><code>function downloadAndSave($urlS,$pathS)
{
    $fp = fopen($pathS, 'w');    
    $ch = curl_init();

    curl_setopt($ch,CURLOPT_PROXY,"http://test:1234");
    curl_setopt($ch,CURLOPT_PROXYPORT,1234);
    curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, 0);
    curl_setopt($ch,CURLOPT_URL,$urlS);
    curl_setopt($ch, CURLOPT_FILE, $fp);
    $data = curl_exec($ch);

    fclose($fp);    
}
</code></pre>

<p>I have tried using CURLOPT_CONNECTTIMEOUT but no difference. Any other way to prevent this?</p>

<p>Thanks In Advance</p>
