php - cURL takes long time to start download -


i'am trying download file (1gb) on server c via server b, has code:

header("content-disposition: attachment; filename=how use git , github videos.zip"); header("content-type: application/octet-stream"); header("content-transfer-encoding: binary");  $url = "http://zips.udacity-data.com/ud775/how%20to%20use%20git%20and%20github%20videos.zip";  $ch = curl_init();  curl_setopt($ch, curlopt_url, $url); curl_setopt($ch, curlopt_header, 0); curl_setopt($ch, curlopt_buffersize, 256);  curl_exec ($ch); curl_close($ch); 

i expecting momentally start dwonlaoding file. instead have wait long time till browser window ask save it. thought curl_setopt($ch, curlopt_buffersize, 256); means transfer file chunk chunk don'thave wait read file first.

so why takes long time start download? how can fix it? if method wrong please suggest me else

that's because curl_exec() blocks till reads full response (consuming 1gb of memory in process in case). can make call own function however:

curl_setopt($ch, curlopt_writefunction, function($ch, $buffer) {   echo $buffer;   return strlen($buffer); }); curl_exec ($ch); // curl call curlopt_writefunction receives data inside curl_exec() 

be sure curlopt_returntransfer not set @ all, neither false, neither true.


Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -