Jump to content

Get and Post request in PHP with RollingCurl library


konkhra

Recommended Posts

For the given simple php script how can I use RollingCurl library to make POST request for each of www.site_01.com, www.site_02.com and www.site_03.com using parsed variables catched with "my_request" function from the GET request ? Thank you.

 

 

<?
require("RollingCurl.php");

function my_request($response) {

  ...............
  ...............

(code used to parse some variables to use later in POST request)

  ...............
  ...............


}

$urls = array("http://www.site_01.com",
              "http://www.site_02.com",
              "http://www.site_03.com");

$rc = new RollingCurl("my_request");

$rc->window_size = 3;

foreach ($urls as $url) {
    $request = new RollingCurlRequest($url, "GET");
    $rc->add($request);
}

$rc->execute();
?>

Link to comment
Share on other sites

What is RollingCurl? Never heard of it. You would probably do better to either post this in the proper section (3rd Party Scripts) or actually posting / asking the actual developer(s) of RollingCurl for help, as they would know their system better than we would.

Link to comment
Share on other sites

What is RollingCurl? Never heard of it. You would probably do better to either post this in the proper section (3rd Party Scripts) or actually posting / asking the actual developer(s) of RollingCurl for help, as they would know their system better than we would.

 

RollingCurl is a way for processing multiple HTTP requests in parallel in PHP. Being a beginner in php I don't know how to use that library to fit my needs. I searched over the internet for similar examples but with no success

Link to comment
Share on other sites

Here is the basics to do multiple urls

 

<?php
function request_callback($response, $info) {
print_r($info);
echo "<hr>";
}

require("RollingCurl.php");

echo "<hr>";

$urls = array("http://phpfreaks.com",
              "http://www.facebook.com",
              "http://www.yahoo.com",
              "http://www.youtube.com",
              "http://www.live.com",
              "http://www.wikipedia.com",
              "http://www.msn.com",
              "http://www.yahoo.co.jp",
              "http://www.myspace.com",
              "http://www.twitter.com",
              "http://www.microsoft.com");
              
$rc = new RollingCurl("request_callback");
$rc->window_size = 20;
foreach ($urls as $url) {
    $request = new RollingCurlRequest($url);
    $rc->add($request);
}
$rc->execute();
?>

 

For parsing or other information needed for each url, you get it the same way as any other normal curl request.

 

Add whatever you need in the request_callback function

Link to comment
Share on other sites

Here it is with using a text area for multiple urls, I didn't spend any time styling this or anything, but to show you how can do it.

 

<form name="input" action="" method="post">
<textarea cols="100" rows="10" name="url" placeholder="Place urls each line" value="<?php echo $_POST['url'];?>"/><?php echo $_POST['url'];?></textarea>
<input type="submit" value="fetch urls"/>
</form> 

<?php
if(isset($_POST['url']) && $_POST['url'] != ''){

function request_callback($response, $info) {
print_r($info);
echo "<hr>";
}

$url_values = array();
$show_urls = str_replace(array(",","\r",",\n "," "), "|",$_POST['url']);
$urls_array = explode("|",$show_urls);
foreach($urls_array as $urls){
if($urls != ''){
$url_values[] = trim($urls);
}
}

require("RollingCurl.php");

echo "<hr>";

$rc = new RollingCurl("request_callback");
$rc->window_size = 20;
foreach ($url_values as $url) {
    $request = new RollingCurlRequest($url);
    $rc->add($request);
}
$rc->execute();

}
?>

Link to comment
Share on other sites

  • 5 months later...
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.