I have the following code snippet taken from the PHP manual on curl_multi_ * entries:
$active = null;
do {
$process = curl_multi_exec($curl, $active);
} while ($process === CURLM_CALL_MULTI_PERFORM);
while (($active >= 1) && ($process === CURLM_OK))
{
if (curl_multi_select($curl, 3) != -1)
{
do {
$process = curl_multi_exec($curl, $active);
} while ($process === CURLM_CALL_MULTI_PERFORM);
}
}
Now I really don't like to write ... while loops, and I was wondering what would be a better and shorter way to achieve the same, but without using such loops.
So far I have come up with a slightly longer version, but I'm not sure if it does the same or if it works the same as the original one:
while (true)
{
$active = 1;
$process = curl_multi_exec($curl, $active);
if ($process === CURLM_OK)
{
while (($active >= 1) && (curl_multi_select($curl, 3) != -1))
{
$process = CURLM_CALL_MULTI_PERFORM;
while ($process === CURLM_CALL_MULTI_PERFORM)
{
$process = curl_multi_exec($curl, $active);
}
}
break;
}
else if ($process === CURLM_CALL_MULTI_PERFORM)
{
continue;
}
break;
}
Thanks in advance.
source
share