Total Pageviews

Monday, June 13, 2011

hit multiple times on the target address using CURL in php multi treading .....

Follow kvn_krishna on Twitter

 this program used to hit the target ftp/http/https........hit  at multiple times... will getta response from multiple times.....i hope  this is example useful for u.... 

example:-

<?php
error_reporting(0);
  // create the multi curl handle
  $mh = curl_multi_init();
  $handles = array();

  for($i=0;$i<5;$i++)
  {
    // create a new single curl handle
    $ch = curl_init();
 
    // setting several options like url, timeout, returntransfer
    // simulate multithreading by calling the wait.php script and sleeping for $rand seconds
    curl_setopt($ch, CURLOPT_URL, "http://www.example.com/IPtest/Timeout.asmx/HelloWorld");
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch , CURLOPT_POSTFIELDS,"test='($i+1)'&value='ram'");
    curl_setopt($ch, CURLOPT_TIMEOUT, 30);
 
    // add this handle to the multi handle
    curl_multi_add_handle($mh,$ch);
 
    // put the handles in an array to loop this later on
    $handles[] = $ch;
  }

  // execute the multi handle
  $running=null;
  do
  {
    curl_multi_exec($mh,$running);
    // added a usleep for 0.25 seconds to reduce load
    usleep (250000);
  } while ($running > 0);

  // get the content of the urls (if there is any)
  for($i=0;$i<count($handles);$i++)
  {
    // get the content of the handle
    $output=curl_multi_getcontent($handles[$i]);
 
    // remove the handle from the multi handle
    curl_multi_remove_handle($mh,$handles[$i]);
//echo the output to the screen multiple times
echo $output."<br>";

  }

  // echo the output to the screen
// echo $output;

  // close the multi curl handle to free system resources
  curl_multi_close($mh);


?>

No comments:

Post a Comment