Hi,
I am having this problem, I am retrieving some data from a MySQL DB, and
using it to post a cURL, what I am calling is a web service, and I have
3 options to do it: SOAP, GET and POST, I am not very familiar with
SOAP, so I am using POST, in response I get a XML on each call to the
web service.
If I call only one curl and web service each time, then everything works
just perfect, but if I try to make multiple calls then I get weird
results, I get some responses OK (an XML), but others are empty responses.
The first three responses are always empty, I don't get any errors,
instead only those empty responses (no XML).
Ok, I'm posting the code right here:
$sql_aero = "SELECT
code
FROM
airports
ORDER BY
id ASC
limit 0, 10";
$result_aero = mysql_query($sql_aero);
$num_results_aero = mysql_num_rows($result_aero);
if (!empty($num_results_aero)) {
$i = 0;
$mh = curl_multi_init();
while($row_aero = mysql_fetch_array($result_aero)) {
$aero = $row_aero["code"];
$ws =
"www.webservicex.com/airport.asmx/getAirportInformationByAirportCode";
$post = "airportCode=$aero";
print "$i = $aero, $post<br>";
$conn[$i] = curl_init($ws);
curl_setopt($conn[$i], CURLOPT_RETURNTRANSFER, 1);
curl_setopt($conn[$i], CURLOPT_POSTFIELDS, $post);
curl_multi_add_handle ($mh, $conn[$i]);
$i++;
}
}
do {
$mrc = curl_multi_exec($mh, $active);
} while ($mrc == CURLM_CALL_MULTI_PERFORM);
for ($j=0; $j<$i; $j++) {
if (($err = curl_error($conn[$j])) == '') {
$res[$j] = curl_multi_getcontent($conn[$j]);
print "$j<br>$newstr[$j]";
}
else {
print "Curl error on handle $j: $err\n";
}
curl_multi_remove_handle($mh, $conn[$j]);
curl_close($conn[$j]);
}
curl_multi_close($mh);
As you won't have the DB, if want to try the code, use this array with
the proper change to the code:
$airports = ['LAX', 'ATL', 'JFK', 'SAN', 'CDG', 'MAD', 'BCN', 'GDL',
'TIJ', 'SYD'];
I am working on Localhost: Windows, Apache 2.2.3, PHP 5.1.6 and MySQL 5.0.24
here's the original code:
http://www.php.net/manual/en/function.curl-multi-exec.php
Regards!
hugo Hiram.
---
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php