来自 PHP 的 cURL 2 初始化

cURL 2 init from PHP

请帮忙!我哪里错了?

在 $rty 中我有数组 url

我明白我在过去 2 段代码中遇到的问题,但我不知道在哪里

尽管这很奇怪,因为我通过示例完成了第二部分

也许我不能做两个 int 但我不明白为什么如果我通过 curl_close

关闭会话

谢谢大家的帮助和回答

    $headers2 = array(
   "Accept: application/json",
   "Ocp-Apim-Subscription-Key: 85888888888888888888",
);

$ch2 = curl_init("https://api.wto.org/qr/v1/notifications?locale=en&type=complete-notification&status=published");
function ex_curl_setopt($ch2, int $option2, $val2): void
{
    if (!curl_setopt($ch2, $option2, $val2)) {
        throw new \RuntimeException("curl_setopt failed: " . curl_errno($ch2) . ":" . curl_error($ch2));
    }
}
curl_setopt($ch2, CURLOPT_HTTPHEADER, $headers2);
curl_setopt($ch2, CURLOPT_RETURNTRANSFER, true);

$response2 = curl_exec($ch2);
if(curl_errno($ch2)){
    throw new \RuntimeException("curl_exec failed: ".curl_errno($ch2).": ".curl_error($ch2));
}
curl_close($ch2);



$data2 = json_decode($response2, true, 999, JSON_THROW_ON_ERROR);

$rty = [];
  foreach ($data2['data'] as $links) {
$rty[] = $links['details'];  
  }



$multi = curl_multi_init();
$handles = [];


foreach ($rty as $newdata) {
    $ch = curl_init ($newdata);
    
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers2);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

    curl_multi_add_handle ($multi, $ch);
    $handles[$newdata] = $ch; 
}

do {
    $mrc = curl_multi_exec($multi, $active);
} while ($mrc = CURLM_CALL_MULTI_PERFORM);

while ( $active && $mrc = CURLM_OK)
{
if (curl_multi_select ($multi)= -1) {
    usleep(100);
    } 
do {
    $mrc = curl_multi_exec ($multi, $active);
} while ($mrc = CURLM_CALL_MULTI_PERFORM);
}

foreach ($handles as $channel) {
    $html = curl_multi_getcontent($channel);
    var_dump($html);
    curl_multi_remove_handle ($multi, $channel);
}

curl_multi_close ($multi);

在这种情况下无法在写入上下文中使用函数 return 值

if (curl_multi_select ($multi)= -1)

$multi = curl_multi_init();
$handles = [];


foreach ($rty as $newdata) {
    $ch = curl_init ($newdata);
    
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers2);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

    curl_multi_add_handle ($multi, $ch);
    $handles[$newdata] = $ch; 
}

do {
    $mrc = curl_multi_exec($multi, $active);
} while ($mrc == CURLM_CALL_MULTI_PERFORM);

while ( $active && $mrc == CURLM_OK)
{
if (curl_multi_select ($multi)== -1) {
    usleep(100);
    } 
do {
    $mrc = curl_multi_exec ($multi, $active);
} while ($mrc == CURLM_CALL_MULTI_PERFORM);
}

foreach ($handles as $channel) {
    $html = curl_multi_getcontent($channel);
var_dump($html);
    curl_multi_remove_handle ($multi, $channel);
}

curl_multi_close ($multi);