curl only hitting the last url in the list

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
strannik_au
Forum Newbie
Posts: 3
Joined: Sun Oct 26, 2008 8:10 pm

curl only hitting the last url in the list

Post by strannik_au »

Got a wierd thing happening.

Consider following code:

Code: Select all

 
$ip_list = file("iplist.txt");
foreach($ip_list as $ip) {
      $url = "http://".$ip."/startPaymentAgent.php";
    echo "Starting agent on ". $ip."<br>";
    $options = array(
    CURLOPT_RETURNTRANSFER => true, // return web page
    CURLOPT_HEADER => false, // don't return headers
    CURLOPT_USERAGENT => "spider", // who am i
    CURLOPT_CONNECTTIMEOUT => 5, // timeout on connect
    CURLOPT_TIMEOUT => 1, // timeout on response
    );
 
    $ch = curl_init( $url );
    curl_setopt_array( $ch, $options );
    curl_exec( $ch );
    $err = curl_errno( $ch );
    $errmsg = curl_error( $ch );
    echo $errmsg."<br>";
    curl_close( $ch );
    echo "Started agent on ". $ip."<br>";
}
 
text file contains a list of IPs which it should hit.
Now what's happening is that it only hits the last IP in the list.
Here is the output of this script:

Code: Select all

Starting agent on 10.49.114.94 
 
Started agent on 10.49.114.94 
Starting agent on 10.49.114.88
Operation timed out after 1 seconds with 0 bytes received
Started agent on 10.49.114.88
Any ideas why it would do this? I'm at a loss right now.
That's PHP 5.2.6
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: curl only hitting the last url in the list

Post by requinix »

Only problem I see is that 10.49.114.88 is being slow and cURL is timing-out.
strannik_au
Forum Newbie
Posts: 3
Joined: Sun Oct 26, 2008 8:10 pm

Re: curl only hitting the last url in the list

Post by strannik_au »

I solved the problem by using socket instead, but still would be nice to know why curl behaves that way.
strannik_au
Forum Newbie
Posts: 3
Joined: Sun Oct 26, 2008 8:10 pm

Re: curl only hitting the last url in the list

Post by strannik_au »

It's designed to be slow.
startPaymentAgent.php executes a program, which is not going to come back for quite a while
88 is actually the one that comes up, 94 is the one which doesn't start
if i add mor eip's to the list, last one will be the one that starts up, the rest will not
Post Reply