Curl script execution

my script uses curl to upload images to smugsmug via the smugsmug api . I go through the folder and upload each image. but after 3-4 downloads curl_exec will fail, stop everything and prevent other images from loading.

$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);

update: so I added an entry to my script. when it fails, the log 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);
+3
source share
5 answers

Not sure what the problem is ... What is the answer when it fails? What do the system and apache logs say?

, , curl_init() curl_close() . - itsef curl_set_opt, url curl_exec(). , - - . / , curl_multi / .

+3

, , , -.

, , - .

- cURL CURLOPT_TIMEOUT

, - script set_time_limit()

+1

, curl_error():

$upload_result = curl_exec($ch); //fails here

$error = curl_error($ch();    
if ($error) echo "CURL Error: $error";

curl_close($ch);

, phpinfo();, , ( display_errors).

0

1- Force Curl, ,

curl_setopt($ch, CURLOPT_VERBOSE, true);
curl_setopt($ch, CURLOPT_HEADER, true);

2- , , PHP , script:

<?php
ini_set('display_errors', '1');
error_reporting(E_ALL);

3 script CLI.

4- , , runl exec().

<?php

$curl_str = "curl -k -o /my/path/curl_output.log -d 'var1=".$value1."&var2=".$value2."& etc...' https://upload.smugmug.com/services/api/rest/1.2.2/";
$r = exec($curl_str);
0

Source: https://habr.com/ru/post/1731043/


All Articles