tags:

views:

66

answers:

3

Hi, I am using curl, I am wondering how would I send post/submit data on my page to those websites? The web site has "host, time, port". My MYSQL database has a list of urls. I was thinking of curl_multi but I am not sure.

Please someone post examples. It has to be a fast method.

Basically feteches the url and post.

while($resultSet = mysql_fetch_array($SQL)){                
    $ch = curl_init($resultSet['url'] . $fullcurl);
    curl_setopt($ch, CURLOPT_TIMEOUT, 2);           
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
}
+1  A: 

The PHP cURL reference says that the CURLOPT_POST option, set to true, makes it a POST request. CURLOPT_POSTFIELDS sets the fields that you will send in foo=bar&spam=eggs format (which one can build from an array with http_build_query).

curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, 'foo=bar&spam=eggs');
Matchu
I already have something similar "$fullcurl = "?host="$fullcurl = "?here=".$here."". Any more help?
Raymond
A: 

Give this a shot:

while ($resultSet = mysql_fetch_assoc($SQL)) {
  $ch = curl_init($resultSet['url']);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
  curl_setopt($ch, CURLOPT_TIMEOUT,2);
  curl_setopt($ch, CURLOPT_POST, true);
  curl_setopt($ch, CURLOPT_POSTFIELDS, $fullcurl);
  $response = curl_exec($ch);
  curl_close();
}
Fosco
I have this on "$ch = curl_init($resultSet['url'] . $fullcurl);", what would be recommend to replace? Thne I have this coded "curl_multi_add_handle($mh, $ch);"... Confused here. Needing some help again
Raymond
Fosco
A: 

Here is an example on how to do it with curl_multi. Although you should break it up so you only have a certain amount of URLs going out at once (i.e. 30). I added the follow location directive, which you usually want.

$mh = curl_multi_init();
$ch = array();
while($resultSet = mysql_fetch_array($SQL)){                
    $ch[$i] = curl_init($resultSet['url'] . $fullcurl);
    curl_setopt($ch[$i], CURLOPT_TIMEOUT, 2);
    curl_setopt($ch[$i], CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch[$i], CURLOPT_FOLLOWLOCATION, true);
    curl_multi_add_handle($mh, $ch[$i]);
}
$running = null;
do {
    curl_multi_exec($mh,$running);
} while ($running > 0);
$num = count($ch);
for ($i=0; $i<$num; $i++ ) {
    curl_multi_remove_handle($mh, $ch[$i]);
}
curl_multi_close($mh);
Brent Baisley
May I ask, What is these part for? "curl_setopt($ch[$i], CURLOPT_FOLLOWLOCATION, true);" "curl_multi_exec($mh,$running);} while ($running > 0);$num = count($ch);for ($i=0; $i<$num; $i++ ) { curl_multi_remove_handle($mh, $ch[$i]);"
Raymond
Also, "curl_setopt($ch[$i], CURLOPT_TIMEOUT, 2);" I research and found this "usleep(100000);" what does they do? Please add comments on the code.
Raymond