Reputation: 2480
I use multi curl for retrieve some pages, from 1 to 200. The problem is that the firsts links from the List return always Empties! I don't understand WHY!! O_o
$mh = curl_multi_init();
for($j=0; $j<$i; $j++){
$ch[$j] = curl_init($Links[$j]);
curl_setopt($ch[$j], CURLOPT_CONNECTTIMEOUT, $curlConTimeOut);
curl_setopt($ch[$j], CURLOPT_TIMEOUT, $curlTimeOut);
curl_setopt($ch[$j], CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch[$j], CURLOPT_MAXREDIRS, 3);
curl_setopt($ch[$j], CURLOPT_FOLLOWLOCATION, 1);
curl_multi_add_handle($mh, $ch[$j]);
}
$active = null;
do {
$mrc = curl_multi_exec($mh, $active);
} while ($mrc == CURLM_CALL_MULTI_PERFORM);
while ($active && $mrc == CURLM_OK) {
if (curl_multi_select($mh) != -1) {
do {
$mrc = curl_multi_exec($mh, $active);
} while ($mrc == CURLM_CALL_MULTI_PERFORM);
}
}
$Si = 0; $Fi = 0; $Disp = "";
for($j=0; $j<$i; $j++){
if($ch[$j]){
if(curl_multi_getcontent($ch[$j]) == null){
$Disp .= '0';
$Fi++;
}else{
$Disp .= '1';
$Si++;
}
curl_multi_remove_handle($mh, $ch[$j]);
curl_close($ch[$j]);
}
}
curl_multi_close($mh);
$Si / $Fi / $Disp is just for testing, and an example of result is:
Link Success: 65/161
Link Failed : 96/161
Disp: 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001111111111111111101111110011111111001111111111111111111111111111111111
Where 0 is for failed, and 1 for success. If the N element is 0, it means that the N Link is returned NULL
It's impossible that every time, only the initials elements return null!! What's the odds?!?!?! I have ask for curl_error, all with: "Connection timed out after XXXXX milliseconds"!
1°: 13852 milliseconds
2°: 13833 milliseconds ... 12676 ms ... 10195 ... and continues down to 6007ms and after start the right ones!
The CURLOPT_CONNECTTIMEOUT IS SET TO 6sec!
why every time start from an higher number and go to 6, and after return right? O_o I want to underline that the order of the null response depends only from the list! Not from the multicurl time respond!
Another Example with less links:
| Link Success: 30/52
| Link Failed : 22/52
| Disp: 0000000000000000000001111111111011111111111111111111
Upvotes: 3
Views: 473
Reputation: 7762
As you see when you execute/request less content/pages you will hit the 1 faster (1 is success and 0 error).
As I understand from what I hear your first request hit an time out. My guess is that you need to lower the amount of request/executions per time. Lets stay you need to execute 5, get the values and then next 5.
5 is just a number i say, so test which number is beter for you. This number can be bigger if your processor can handle more stuff at the same time. But is also limited to the other side of the internet how fast they respond.
Hope it hels
Upvotes: 0