Please help! Where my mistake?
In $rty i have array url
I understand what i have problem in 2 past of code, but i don't know where
Although this is very strange because I did the second part by example
Maybe I can't do two int but I don't understand why if I close the session each through curl_close
Thank you all for your help and answers
$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);
CodePudding user response:
Can't use function return value in write context in this condition "if (curl_multi_select ($multi)= -1)"
CodePudding user response:
$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);