Click to See Complete Forum and Search --> : Multiple curl_exec
Blizzard84
08-10-2008, 10:38 PM
Are there any issues when executing multiple curl executions?
Calling the script below multiple times.
<?php
// create a new cURL resource
$ch = curl_init();
// set URL and other appropriate options
curl_setopt($ch, CURLOPT_URL, "http://www.example.com/");
curl_setopt($ch, CURLOPT_HEADER, 0);
// grab URL and pass it to the browser
curl_exec($ch);
// close cURL resource, and free up system resources
curl_close($ch);
?>
Thanks
Sheldon
08-10-2008, 10:40 PM
Only server / connection load, IE, you are cURL'ing to 500 domains, it may time out due to the size of the response and the connection speed from your server to theirs.
What sort of issues are you talking about?
Blizzard84
08-10-2008, 10:56 PM
Hi,
Thanks for the quick reply!
Let's say I have a loop which calls a script 6 times.
http://www.example.com/addpass.php
This script adds a password to a file.
I've had some issues when sometimes the password wasn't updated.
Not sure if it timed out or not. Is it possible that the script wasn't finished before the next curl_init was called?
Blizzard84
08-10-2008, 10:58 PM
More information, the script below is ran multiple times.
<?php
// create a new cURL resource
$ch = curl_init();
// set URL and other appropriate options
curl_setopt($ch, CURLOPT_URL, "http://www.example.com/addpass.php");
curl_setopt($ch, CURLOPT_HEADER, 0);
// grab URL and pass it to the browser
curl_exec($ch);
// close cURL resource, and free up system resources
curl_close($ch);
?>
Sheldon
08-10-2008, 11:32 PM
I would make my cURL request in to a function, and my addresses in to an array, then loop through the addresses.
Try something like this
<?php
function foreach_cURL($address){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $address);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_exec($ch);
curl_close($ch);
return true;
}
$addresses = array("http://www.example1.com/addpass.php", "http://www.example2.com/addpass.php", "http://www.example3.com/addpass.php");
foreach($addresses as $address){
if(!foreach_cURL($address)){
die("There was a cURL Error with \"{$address}\"");
}
}
?>
ayvegh
08-11-2008, 12:19 AM
A little OT, but do you know how to use CURL to access a secure page (HTTP authentication - not HTTPS), and return the result, instead of outputting it? TIA