php - Using cURL in a loop -


i'm writing script in unspecified number of files need uploaded via curl requests remote api. however, script hangs , times out. strangely enough, requests successful (the files uploaded), script unable continue. here's loop:

foreach ($paths $path) {   $ch = curl_init($path);   curl_setopt($ch, curlopt_httpheader, array('x-auth-token: '.$token, 'content-length: '.filesize($path));   curl_setopt($ch, curlopt_put, true);   curl_setopt($ch, curlopt_infile, fopen($path, 'r'));   curl_setopt($ch, curlopt_infilesize, filesize($path));   echo curl_exec($ch); } 

i believe has loop. i've tried adding curl_close within loop, doesn't solve problem. ideas?

put timeout in curl

foreach ($paths $path) {   $ch = curl_init($path);   curl_setopt($ch, curlopt_httpheader, array('x-auth-token: '.$token, 'content-length: '.filesize($path));   curl_setopt($ch, curlopt_put, true);   curl_setopt($ch, curlopt_infile, fopen($path, 'r'));   curl_setopt($ch, curlopt_infilesize, filesize($path));   curl_setopt($ch, curlopt_connecttimeout ,0);    curl_setopt($ch, curlopt_timeout, 400); //timeout in seconds   echo curl_exec($ch); } 

Comments

Popular posts from this blog

Winapi c++: DialogBox hangs when breaking a loop -

vb.net - Font adding using PDFsharp -

javascript - jQuery iScroll clickable list elements while retaining scroll? -