gpt4 book ai didi

php - curl 停止脚本执行

转载 作者:可可西里 更新时间:2023-11-01 01:10:35 25 4
gpt4 key购买 nike

我的脚本使用 curl 将图像上传到 smugsmug网站通过 smugsmug api .我循环浏览一个文件夹并上传其中的每张图片。但是在上传 3-4 次之后,curl_exec 会失败,停止一切并阻止其他图像上传。

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

更新:所以我添加了登录到我的脚本。当失败时,日志记录在 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");

我也是

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

最佳答案

不确定是什么问题...失败时的响应是什么?系统和 Apache 日志说了什么?

如果我是你,我不会在循环中使用 curl_init()curl_close()。相反,我会在循环之前初始化,并在循环之后关闭 - 然后在循环本身中我会使用 curl_set_opt 来设置 url 和不同的参数,然后调用 curl_exec() .它甚至可能是所有这些句柄超过某种系统限制或其他东西的问题。如果您需要/想要使用多个连接,您可以使用 curl_multi 或编写一些管理函数/类来管理多个句柄。

关于php - curl 停止脚本执行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2185969/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com