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>";
}
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.88That's PHP 5.2.6