curl halts script execution

Posted by Funky Dude on Stack Overflow See other posts from Stack Overflow or by Funky Dude
Published on 2010-02-02T16:59:08Z Indexed on 2010/05/20 15:30 UTC
Read the original article Hit count: 317

Filed under:
|
|

my script uses curl to upload images to smugsmug site via smugsmug api. i loop through a folder and upload every image in there. but after 3-4 uploads, curl_exec would fail, stopped everything and prevent other images from uploading.

$upload_array = array(
    "method" => "smugmug.images.upload",
    "SessionID" => $session_id,
    "AlbumID" => $alb_id,
    "FileName" => zerofill($n, 3) . ".jpg",
    "Data" => base64_encode($data),
    "ByteCount" => strlen($data),
    "MD5Sum" => $data_md5);
$ch = curl_init();
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); 
curl_setopt($ch, CURLOPT_POSTFIELDS, $upload_array);
curl_setopt(
    $ch, CURLOPT_URL, 
    "https://upload.smugmug.com/services/api/rest/1.2.2/");
$upload_result = curl_exec($ch); //fails here
curl_close($ch);

updated: so i added logging into my script. when it does fail, the logging stops after fwrite($fh, "begin curl\n");

fwrite($fh, "begin curl\n");
$upload_result = curl_exec($ch);
fwrite($fh, "curl executed\n");
fwrite($fh, "curl info: ".print_r(curl_getinfo($ch,true))."\n");
fwrite($fh, "xml dump: $upload_result \n");
fwrite($fh, "curl error: ".curl_error($ch)."\n");

i also

curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 60*60);

© Stack Overflow or respective owner

Related posts about php

Related posts about curl