Total Pageviews

Monday, June 13, 2011

fetch multiple contents with time out using curl with php mutitreading

Follow kvn_krishna on Twitter


this prgm used to fetch  the contents from other servers .... wil set the sleeping time and and will see the time taken and how to fetch ,,, by using curl with php mutitreading
<style type="text/css">
<!--
.style2 {color: #FF0000; font-style:oblique; font-size:24px;}
-->
</style>

<?php
function addHandle(&$curlHandle,$url)
{
$cURL = curl_init();
curl_setopt($cURL, CURLOPT_URL, $url);
curl_setopt($cURL, CURLOPT_HEADER, 0);
curl_setopt($cURL, CURLOPT_RETURNTRANSFER, 1);
curl_multi_add_handle($curlHandle,$cURL);
return $cURL;
}
//execute the handle until the flag passed to function is greater then 0
function ExecHandle(&$curlHandle)
{
$flag=null;
do {
    curl_multi_exec($curlHandle,$flag);//fetch pages in parallel
} while ($flag > 0);
}


$list[1] = "http://www.google.co.in/";
$list[2] = "http://in.yahoo.com/?p=in";
$list[3] = "http://www.rediff.com/";
$list[4] = "http://www.bing.com/";
$curlHandle = curl_multi_init();

for ($i = 1;$i <= 4; $i++)
 $curl[$i] = addHandle($curlHandle,$list[$i]);
ExecHandle($curlHandle);
for ($i = 1;$i <= 4; $i++)
{
// set the sleeping time on 2 seconds
 usleep(2000000);
 {
 // get the content from other servers
 $text[$i] =  curl_multi_getcontent ($curl[$i]);
 echo $text[$i];
  }
 
 echo "<span class='style2'>$i time out".date("h:i:s")."</span>";
}
for ($i = 1;$i <= 4; $i++)//remove the handles
  curl_multi_remove_handle($curlHandle,$curl[$i]);
curl_multi_close($curlHandle);

?>

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);


?>

Friday, June 10, 2011

example code paypal integration with php

Follow kvn_krishna on Twitter
sample code paypal integration with php
these credit gose to  Dan Lawson....

payment gate way integration ..... create test account in paypal....

Follow kvn_krishna on Twitter
Here i just discus about how to integrate payment gateway in php.... before that we have needed to know the checking process.... that followed blow  
step 1. u go to register your account in papal sandbox  
after creation of your account you go to configure ur  account in ur account what kind u want....

after that you need ipn ... so you should follow this steps 

step1.


step2.


this is a sample...... you should your needed path url in ipn header url.....

Monday, June 6, 2011

mutiple email sending seperation usring comma


<?php
if(isset($_REQUEST['submit']))
{
//$toadd = $_REQUEST['to'];
//define the receiver of the email
$to = $_REQUEST['to'];
$array = explode(",", $to);
//define the subject of the email
$subject = $_REQUEST['subject'];
//define the message to be sent. Each line should be separated with \n
$message = $_REQUEST['textarea'];
//define the headers we want passed. Note that they are separated with \r\n
$headers = "From: it.siddarth@gmail.com\r\nReply-To:  it.siddarth@gmail.com";
//send the email
if($to!="")
{
  foreach ($array as $k => $v)
   {
    // echo $v."</br>";
    $mail_sent = @mail( $v, $subject, $message, $headers );
     }
   echo "You have referred the following your friends email ids $to ";
   }
 else
   {
  echo "check ur refferal email_ids";
    }
}
?>
<form id="form_id" method="post" action="mutiplemails.php" >
  <p>Invite Friends Here :
    <input type="text" id="emailq" name="to" />
    <input type="submit" name="submit" value="Invite" />
 subject:
      <input name="subject" type="text"  />
content:
        <textarea name="textarea" rows="5" > </textarea></p>
</form>